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)]
  3. enum Status {
  4. Rich,
  5. Poor,
  6. }
  7. enum Work {
  8. Civilian,
  9. Soldier,
  10. }
  11. fn main() {
  12. // Explicitly `use` each name so they are available without
  13. // manual scoping.
  14. use Status::{Poor, Rich};
  15. // Automatically `use` each name inside `Work`.
  16. use Work::*;
  17. // Equivalent to `Status::Poor`.
  18. let status = Poor;
  19. // Equivalent to `Work::Civilian`.
  20. let work = Civilian;
  21. match status {
  22. // Note the lack of scoping because of the explicit `use` above.
  23. Rich => println!("The rich have lots of money!"),
  24. Poor => println!("The poor have no money..."),
  25. }
  26. match work {
  27. // Note again the lack of scoping.
  28. Civilian => println!("Civilians work!"),
  29. Soldier => println!("Soldiers fight!"),
  30. }
  31. }

See also:

match and use