Back to questions
JuniorTheoryCommon
What happens when this program is built and run?
mod garden {
fn water() {
println!("water");
}
}
fn main() {
println!("start");
garden::water();
}It does not compile
- Expecting
start waterbecausegardensits in the same file asmain: an item withoutpubis private to its module, somainmay not callgarden::water(E0603). - Expecting
startto print before the error: rustc checks the whole program while building, before anything runs, so a private call stops the build and nothing runs.
- Which single word would you add so that the program prints
startandwater? - Could another function inside
gardencallwaterwithout that change?