Modules and Visibility
CONCEPTS:Rust Modules and Visibility
Question Variations
- "What is the difference between a crate and a module?"
- "Does `use` make an item public?"
- "When would you prefer `pub(crate)` over `pub`?"
- "How does Rust's default privacy affect library design?"
Why This Is Asked
Module boundaries shape a Rust crate’s maintainability and API safety. This question tests whether you can organize code around clear responsibilities and understand that privacy is the default rather than an afterthought.
Key Concepts
- A crate is a compilation unit; modules organize names within it.
- Items are private by default to their parent module.
pubexposes an item, whilepub(crate)andpub(super)provide narrower visibility.usebrings a path into scope but does not change visibility.
Question Variations
- “What is the difference between a crate and a module?”
- “Does
usemake an item public?” - “When would you prefer
pub(crate)overpub?” - “How does Rust’s default privacy affect library design?”