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
2
3
// module.rs

pub fn some_module_fn() {}

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
2
3
// In ./module/shared.rs

pub fn shared_fn() {}

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
2
// module.rs
mod shared; // This imports the sub module