A Rust module is a named space for related functions, structs, and other code. Modules help organize growing programs, distinguish names that might otherwise conflict, and make code easier to read. section 14.1
Modules also control access:
- Items inside a module are private by default. Add `pub` to make a function or module accessible from outside its private scope. section 14.1
- A module can contain child modules. Child modules can use items in their parent, while `crate::` starts a path at the crate root and `super::` moves up one module. section 14.1.3
mod print_things {
use std::fmt::Display;
pub fn prints_one_thing<T: Display>(input: T) {
println!("{}", input)
}
}
fn main() {
use print_things::prints_one_thing;
prints_one_thing(6);
prints_one_thing("Trying to print a string...".to_string());
}
This example makes a printing function public, imports it into `main`, and calls it with a number and a string. section 14.1.1


































