module-concept

Rust Parent-module visibility

Allow a helper to be shared within the parent module’s subtree without making it reachable from unrelated parts of the crate. Expected result (not executed): 23 Why: orders is the parent of prices and may use fee. Common mistake: Reading super as the crate root regardless of nesting.

Formal Syntax & Structure

rust syntaxrust
pub(super) fn helper() {}

Working Example

Example Snippetrust
mod orders {    mod prices { pub(super) fn fee() -> u32 { 3 } }    pub fn total() -> u32 { 20 + prices::fee() }}fn main() { println!("{}", orders::total()); }
Rust Reference