Rust Accessing the Parent Module


Example

Sometimes, it can be useful to import functions and structs relatively without having to use something with its absolute path in your project. To achieve this, you can use the module super, like so:

fn x() -> u8 {
    5
}

mod example {
    use super::x;

    fn foo() {
        println!("{}", x());
    }
}

You can use super multiple times to reach the 'grandparent' of your current module, but you should be wary of introducing readability issues if you use super too many times in one import.