
Rust modules seem complicated at first but they are really not
Rust modules easy explanation
When I first started learning Rust I didn't get how modules work at first. After hanging in Rust discord someone gave me a really good explanation.
Think of modules as a way to include the code from other files. In theory it is possible to create everything in one big file. But no one does it. Splitting modules into files is a good practice to help you maintain your project.
mod test {
// your code here
}
When you write:
mod utils;
You are asking rust to find the code either in:
- file called utils.rs
- file mod.rs in utils folder
Knowing these 2 rules lets you define any module structure in your project.