Modules and Visibility
mod groups code and items are private by default. pub makes them public and use brings names into scope. Files can be modules too.
Example
mod shapes {
pub fn area(w: u32, h: u32) -> u32 { w * h }
fn secret() {}
}
use shapes::area;
fn main() {
println!("{}", area(3, 4));
}Result
12
Exercise
Make an item public.
fn area() {}Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.