module-concept

Rust Nested module file layouts

A parent module can live in orders.rs while its child lives in orders/fee.rs. Another supported convention uses orders/mod.rs as the parent file. Choose one parent convention, not both at once. The declaration tree determines the logical names. Multi-file fixture: module-directory. The code shown is one source file, not a standalone program. Expected result (not executed): 17 Why: orders.rs declares fee and the child supplies the amount. Common mistake: Creating both orders.rs and orders/mod.rs for the same module.

Formal Syntax & Structure

rust syntaxrust
orders.rs + orders/fee.rs

Working Example

Example Snippetrust
mod orders;fn main() { println!("{}", orders::total()); }
Rust Reference