Rust Modules: Your Code's File System
Think of Rust modules as a file system for your code, grouping logic and hiding details. You declare them with `mod`, and Rust finds the code in corresponding files. The footgun: items are private by default, so you must use `pub` to expose them.
Rust modules are your primary tool for organizing code and managing privacy, acting like a file system for your crate. They group related logic and, by default, hide implementation details. You declare a module with `mod`, and Rust maps it to a file or directory. To access items, you use paths like `crate::garden::vegetables::Asparagus`. The footgun: everything is private by default. Forgetting `pub` on a module or its contents is a common bug, making them invisible to code that needs them.
Read the original → doc.rust-lang.org
- #rust
- #modules
- #privacy
- #organization
- #compiler
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.