Skip to content

Modules

Projects and code dependencies in Rust are called crates, equivalent to modules in Python. The term modules in Rust allow code to be organized for readability and controlled for privacy. A package contains one or more crates and contains a Cargo.toml file.

  • mod declares a module, which can be nested
  • crate is the root of the module tree, equivalent to cd /
  • super moves up the module tree one node, similar to cd ..
  • use .. as is similar to creating a shortcut or symlink. Rust convention is to bring a function's parent into scope in order to mark function calls as unmistakeably belonging to external code. However, for structs and other data structures the full path is specified.sdfsdf
  • pub use statements are used to construct a convenient API by allowing the namespace to be flattened

Rust 2018

The module system was simplified in Rust 2018.

One of the main changes was the elimination of the extern crate keywords which used to be necessary while importing a crate into a project. The only thing that is necessary now is to add the crate to Cargo.toml