In programming, a namespace is a set of names with their specifications (definitions or declarations). This is pretty ambiguous so their use describes them better than what they are — namespaces are used because many things may share the same name across files and libraries. When we collect names into a namespace, we have it such that no two items in the same name space can share the same name.

If we only use one namespace in a given file, we can specify this. In C++, we can use:

using namespace std // swap out std for a namespace ID

In Rust

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.