I have a couple of private modules within my main.rs file. The modules e.g. load the environment variables and start the server. So they contain things which only the main file should see and use.
Now I want to split up the main file into multiple files, but without bringing the files into public scope. How can I do so?
When I extract the modules in separate files, it seems to me that I have to bring the path of the modules in the global scope to be able to use it from the main file. But then any other module can use those modules, although they are only supposed to be used by the main file. how can I make the modules only visible to the main?
mod foo {
mod bar {}
mod baz {}
pub fn main() {
println!("Hello");
}
}
// can't see `bar` or `baz` here
fn main() {
foo::main()
}
// Or just use following if you are on latest stable
// use foo::main;
Currently I almost have it like you suggest. The difference is that I have bar and baz not wrapped within foo. In the end I want to have bar and baz in separate files. But this should be possible now as I see your code. i'll try something.