Here's my file structure:
src
├── [2.4K] game_of_life.rs
├── [1.7K] main.rs
└── [1.9K] preset.rs
File contents:
preset.rs:
pub struct Preset {
...
}
impl Preset {
...
}
I tried importing Preset in main.rs:
mod preset;
And it worked fine.
After that I tried to import Preset in game_of_life.rs using the same line of code, but got an error:
Error: file not found for module `preset`
Help: name the file either game_of_life/preset.rs or game_of_life/preset/mod.rs inside the directory "src"
I don't understand why Rust is trying to find the preset in game_of_life.
I found, that I have to wrap Preset in pub mod preset, but this didn't help me.
I found an answer:
I just had to use use crate::preset::Preset. To understand how and why this works read the first comment under my question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With