The Rust module system organizes code into hierarchical namespaces using mod declarations and controls visibility with pub and use statements. Modules map to files or inline blocks, allowing you to group related functionality while keeping internal details private by default.
mod calculator {
fn add(a: i32, b: i32) -> i32 { a + b }
pub fn subtract(a: i32, b: i32) -> i32 { a - b }
}
fn main() {
// calculator::add() is private and inaccessible here
let result = calculator::subtract(10, 5);
}