module-concept

Rust Private items and descendants

Keep internal helpers out of callers’ reach. An ordinary private item can be used inside its defining module and descendants. A sibling or parent cannot directly use a child’s private helper just because it is in the same crate. Expected result (not executed): 250 Why: The child report can use the private helper in its ancestor. Common mistake: Treating private as visible everywhere in the crate.

Formal Syntax & Structure

rust syntaxrust
fn helper() {}

Working Example

Example Snippetrust
mod billing {    fn cents() -> u32 { 250 }    pub mod report { pub fn total() -> u32 { super::cents() } }}fn main() { println!("{}", billing::report::total()); }
Rust Reference