You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-13 17:44:20 +02:00
25 lines
396 B
Markdown
25 lines
396 B
Markdown
![]() |
# Modules
|
||
|
|
||
|
We have seen how `impl` blocks lets us namespace functions to a type.
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
```
|