Modules in Rust 2018
Modules in Rust 2018
https://doc.rust-lang.org/nightly/edition-guide/rust-2018/module-system/path-clarity.html
Rust 2015
.
├── lib.rs
└── foo/
├── mod.rs
└── bar.rs
Rust 2018
.
├── lib.rs
├── foo.rs
└── foo/
└── bar.rs
In top level, the same level of the main.rs
1 | // module.rs |
Then if you want to add more stuff in the module, helper functions, sub-modules, add them in the folder named the same name as your module.
1 | // In ./module/shared.rs |
To make sure the sub module can be accessed by others, you need to add the module in the top level file as well:
1 | // module.rs |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.