Rust has modules that organise code within a crate, mainly for readability and reuse, specified with mod
. These function similarly to C++ namespaces. We access components with module::member()
, and can load a given module into scope with the use
keyword.
Modules also function to control the access of items. By default, code within modules are private. To make things public, we can declare with pub mod
instead of mod
, or the specific members as pub
.
The keywords pub use
re-export names into the new scope, i.e., we bring an item into scope but also make it available for others to bring into their scope.