use - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# use

The `use` declaration can be used to avoid typing the full module path to access a name:

    // An attribute to hide warnings for unused code.
    #![allow(dead_code)]

    enum Stage {
        Beginner,
        Advanced,
    }

    enum Role {
        Student,
        Teacher,
    }

    fn main() {
        // Explicitly `use` each name so they are available without
        // manual scoping.
        use Stage::{Beginner, Advanced};
        // Automatically `use` each name inside `Role`.
        use Role::*;

        // Equivalent to `Stage::Beginner`.
        let stage = Beginner;
        // Equivalent to `Role::Student`.
        let role = Student;

        match stage {
            // Note the lack of scoping because of the explicit `use` above.
            Beginner => println!("Beginners are starting their learning journey!"),
            Advanced => println!("Advanced learners are mastering their subjects..."),
        }

        match role {
            // Note again the lack of scoping.
            Student => println!("Students are acquiring knowledge!"),
            Teacher => println!("Teachers are spreading knowledge!"),
        }
    }

### See also:

`match` and `use`