use
The use declaration can be used so manual scoping isn’t needed:
1. // An attribute to hide warnings for unused code.
2. #![allow(dead_code)]
4. enum Status {
5. Rich,
6. Poor,
7. }
9. enum Work {
10. Civilian,
11. Soldier,
12. }
14. fn main() {
15. // Explicitly `use` each name so they are available without
16. // manual scoping.
17. use Status::{Poor, Rich};
18. // Automatically `use` each name inside `Work`.
19. use Work::*;
21. // Equivalent to `Status::Poor`.
22. let status = Poor;
23. // Equivalent to `Work::Civilian`.
24. let work = Civilian;
26. match status {
27. // Note the lack of scoping because of the explicit `use` above.
28. Rich => println!("The rich have lots of money!"),
29. Poor => println!("The poor have no money..."),
30. }
32. match work {
33. // Note again the lack of scoping.
34. Civilian => println!("Civilians work!"),
35. Soldier => println!("Soldiers fight!"),
36. }
37. }
