mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-12-16 14:53:28 +02:00
fe21b773e7
* A few speaker notes in Day2: Afternoon and minor cosmetic changes. * Do not test filesystem example code block.
726 B
726 B
Modules
We have seen how impl
blocks let us namespace functions to a type.
Similarly, mod
lets us namespace types and functions:
mod foo {
pub fn do_something() {
println!("In the foo module");
}
}
mod bar {
pub fn do_something() {
println!("In the bar module");
}
}
fn main() {
foo::do_something();
bar::do_something();
}
- Packages provide functionality and include a
Cargo.toml
file that describes how to build a bundle of 1+ crates. - Crates are a tree of modules, where a binary crate creates an executable and a library crate compiles to a library.
- Modules define organization, scope, and are the focus of this section.