Modules
mod groups code and pub makes items public. Use paths and use to bring names in.
Example
mod shapes {
pub fn area(w: u32, h: u32) -> u32 { w * h }
}
fn main() {
println!("{}", shapes::area(3, 4));
use shapes::area as a;
println!("{}", a(2, 2));
}Result
12 4
Exercise
Make public.
fn area() {}Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.