What are Rust modules and the use statement?
Answer
Rust's module system organizes code into a tree of namespaces. Declare an inline module with mod my_module { ... } or in a separate file src/my_module.rs (or src/my_module/mod.rs for a directory module). Items (functions, structs, enums) are private by default; use pub to make them accessible from outside the module. The use statement brings items into scope to avoid fully qualified names: use std::collections::HashMap;. Use use with aliases: use std::io::Result as IoResult;. The pub use combination re-exports items from the current module, building a clean public API surface that hides internal module organization from library consumers.
Previous
What is the difference between String and &str in Rust?
Next
What are if let and while let in Rust?