keyword
Rust super: refer to the parent module
Use `super::` inside a module path to start at its immediate parent module. This is convenient for sharing helpers within a module tree. Expected output (not executed): 12 Why: The checkout module accesses tax from its parent shop module. Common mistake: `super` is not class inheritance; the crate root has no parent module.
Formal Syntax & Structure
rust syntaxrust
super::itemWorking Example
Example Snippetrust
mod shop { fn tax() -> u32 { 2 } pub mod checkout { pub fn total() -> u32 { 10 + super::tax() } }}
fn main() { println!("{}", shop::checkout::total());}