module-concept
Rust Ancestor-scoped visibility
Select a specific ancestor module as the access boundary when one parent level is insufficient. In the 2024 edition the path begins with crate, self or super, and names an ancestor directly rather than an imported alias. Expected result (not executed): 36 Why: The caller lies inside the designated ancestor module. Common mistake: Choosing an unrelated sibling as the visibility boundary.
Formal Syntax & Structure
rust syntaxrust
pub(in crate::orders) fn fee() {}Working Example
Example Snippetrust
mod orders { mod internal { pub mod fees { pub(in crate::orders) fn fee() -> u32 { 6 } } } pub fn total() -> u32 { 30 + internal::fees::fee() }}fn main() { println!("{}", orders::total()); }