app.rs contains a pub trait App and in the firework.rs I'm trying to implement this trait. But I don't know how to refer to the App trait, what path to it is correct, and I get the error maybe a missing crate 'app'.
It was quite easy to use the Firework struct in the main.rs, I just use crate::firework::Firework; but that doesn't work for the app.rs file neither in main.rs nor in firework.rs file.
I tried a dozen different methods like creating a mod.rs and declaring pub mod app; inside, renaming files and example directory, creating a separate directory for the app.rs etc. but none of them worked.
I know the examples directory is not the best place for the App trait, I'll move it to the src soon but for now I'm just interested in how to make this particular case work.
For those who may face the same issue in future: to use the module you need to declare it first with the mod ****; or pub mod ****; statement. And if you have a directory called firework next to your main.rs or lib.rs file that means you need to declare a mod firework; and this directory must contain the mod.rs file where you can declare or implement public modules, functions etc.
Yes, definitely. In case there's a ./src/firework.rs I can just declare it in the main.rs or lib.rs. But if I want to group several modules in a folder, as far as I know, that folder must contain a mod.rs file, am I right?
That used to be the case, but since Rust 2018, the following directory layouts are treated the same:
src/
main.rs (contains the 'mod firework' declaration)
firework.rs (contains the 'mod my_submodule' declaration)
firework/
my_submodule.rs
src/
main.rs (contains the 'mod firework' declaration)
firework/
mod.rs (contains the 'mod my_submodule' declaration)
my_submodule.rs
This saves you from having to move/rename a module if you decide to add submodules to it later on. The fact this was changed is probably why there's not much mention of mod.rs in the current version of the book
Ahh, I understood finally, that's really handy Thanks for your explanations, now I'm going to get rid of all mod.rs files from my project
UPD: if I don't want to keep all mod files directly in the src directory then I'll still need to use mod.rs, won't I? There will be too many files in the src then