Managing growing projects with packages, crate and modules
These features, sometimes collectively referred to as the module system, include:
Packages: A Cargo feature that lets you build, test, and share crates
Crates: A tree of modules that produces a library or executable
Modules and use: Let you control the organization, scope, and privacy of paths
Paths: A way of naming an item, such as a struct, function, or module
Packages and crates
When we entered the command, Cargo created a Cargo.toml file, giving us a package.
Looking at the contents of Cargo.toml, there’s no mention of src/main.rs because
Cargo follows a convention that src/main.rs is the crate root of a binary crate
with the same name as the package. Likewise, Cargo knows that if the package
directory contains src/lib.rs, the package contains a library crate with the same
name as the package, and src/lib.rs is its crate root.
Modules to control scope and privacy
Paths for referering to an item in the module tree
A path can take two forms:
An absolute path starts from a crate root by using a crate name or a literal crate.
A relative path starts from the current module and uses self, super, or an identifier in the current module.
Bringing paths into scope with the use keyword
Using external packages
Adding rand as a dependency in Cargo.toml tells Cargo to download the rand package
and any dependencies from crates.io and make rand available to our project.