While going through the modules and crate part of the rust programming language book, I got a little bit confused regarding the verbiage used to convey how functions are accessed from their modules.
mod front_of_house {
pub mod hosting {
pub fn add_to_waitlist() {}
}
}
pub fn eat_at_restaurant() {
// Absolute path
crate::front_of_house::hosting::add_to_waitlist();
// Relative path
front_of_house::hosting::add_to_waitlist();
}
The above snippet is put in the crate root file at src/lib.rs
. The book then says something like this:
The
front_of_house
module isn’t public, but because theeat_at_restaurant
function is defined in the same module asfront_of_house
(that is,eat_at_restaurant
andfront_of_house
are siblings), we can refer tofront_of_house
fromeat_at_restaurant
.
But how is eat_at_restaurant
defined in the same module as front_of_house
? It's clearly defined outside front_of_house
module. Were they trying to say that they're defined in the same file or something? Can any of you guys help me understand this?
Thanks in advance!