Access Names Defined Outside Module

Viewed 46

Full working example:

How do you access "Example" from inside the "tests" module?

src/main.rs:

struct Example {}

#[cfg(test)]
mod tests {
    #[test]
    fn example() {
        // Example is out of scope
    }
}
1 Answers

You can access parent module's namespace with super:

struct Example {}

#[cfg(test)]
mod tests {

    use super::Example;

    #[test]
    fn example() {
        // Example is out of scope
    }
}
Related