1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-19 00:43:18 +02:00
comprehensive-rust/src/modules.md

33 lines
726 B
Markdown
Raw Normal View History

2022-12-21 16:36:30 +01:00
# Modules
2023-01-04 15:44:37 +01:00
We have seen how `impl` blocks let us namespace functions to a type.
2022-12-21 16:36:30 +01:00
Similarly, `mod` lets us namespace types and functions:
```rust,editable
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();
}
```
<details>
* 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.
</details>