educative.io

Educative

Why use pub in example about modules?

   pub mod chapter { <---------------------------------- why ?
        pub mod lesson { // mod level 1
            pub mod heading { // mod level 2
                pub fn illustration() {  // mod level 3
                  println!("Hi, I'm a 3rd level nested function");
                }
            }
        }
    }
    fn main() {
        chapter::lesson::heading::illustration(); // call the function
    }

If the module is to be made accessible then it should be made public by using the pub keyword before the mod.

Anum Hassan | Developer Advocate
educative.io