project_template/
another_mod.rs

1pub(self) mod private_mod {
2    pub(super) mod pub_in_super {
3        pub(in crate::another_mod) fn pub_in_file() {
4            println!("called `pub_in_super::pub_in_file()`");
5        }
6
7        pub fn pub_in_anywhere() {
8            println!("called `pub_in_super::pub_in_anywhere()`");
9        }
10    }
11
12    /// pub_in_user::pub_in_anywhere is visible anywhere.
13    /// it's visible in user code if and only if
14    /// all the ancestor modules are also visible in user code.
15    pub use pub_in_super::pub_in_anywhere;
16
17    // compile error because pub_in_file is public in file but
18    // in private_mod.
19    // pub use pub_in_super::pub_in_file;
20}
21
22#[allow(dead_code)]
23pub(crate) fn pub_in_crate() {
24    private_mod::pub_in_super::pub_in_file();
25    self::private_mod::pub_in_super::pub_in_file();
26    super::another_mod::private_mod::pub_in_super::pub_in_file();
27    crate::another_mod::private_mod::pub_in_super::pub_in_file();
28    self::private_mod::pub_in_super::pub_in_anywhere();
29    self::private_mod::pub_in_anywhere();
30    super::private_function();
31}
32
33/// tests should be private in moodule.
34#[cfg(test)]
35pub(self) mod tests {
36    // use super::eat_at_restaurant;
37
38    #[test]
39    fn visibility() {
40        use super::pub_in_crate;
41        pub_in_crate();
42        // this function is  public in super because it's
43        // public in crate.
44    }
45}