I'm totally new to Rust and in the early steps of learning the language.
As such, I'm reading The book while also following along the examples in Rust by Example, and I came across some behavior that puzzles me and I would hope to get an explanation for.
The chapter 3.2.1 has the following example code:
enum Status {
Rich,
Poor,
}
fn main() {
use crate::Status::{Poor, Rich};
let status = Poor;
match status {
// Note the lack of scoping because of the explicit `use` above.
Rich => println!("The rich have lots of money!"),
Poor => println!("The poor have no money..."),
}
}
which, as expected, returns:
The poor have no money...
However, I was experimenting a bit and altered the code to:
enum Status {
Rich,
Poor,
}
fn main() {
use crate::Status::Poor;
let status = Poor;
match status {
// Note the lack of scoping because of the explicit `use` above.
Rich => println!("The rich have lots of money!"),
Poor => println!("The poor have no money..."),
}
}
I was half-expecting a compile-error, but what I didn't understand is, why that code gives me:
The rich have lots of money!
Can somebody explain to me, what is going on here?