Let's say that I have this file structure in my project:
.
├── Cargo.lock
├── Cargo.toml
├── src
│ ├── hotel
│ │ ├── guest.rs
│ │ ├── hotel_manager.rs
│ │ └── hotel.rs
│ ├── lib.rs
│ └── main.rs
In hotel_menager I declared only that I will use hotel and guest module:
pub mod hotel;
pub mod guest;
Then inside lib.rs I declared that I will use hotel_manager module:
pub mod hotel_manager;
and in the end I wanted to use hotel and guest in my main.rs binary but I am getting this error :
file not found for module
hotel_manager
Then I thought that maybe I should use use but it also didn't help at all:
use crate::hotel::hotel_manager;
unresolved import
crate::hotel.
My Cargo.toml:
[package]
name = "learn_file_spliting"
version = "0.1.0"
authors = ["kaczor6418 <[email protected]>"]
edition = "2018"
[lib]
name = "lib"
path = "src/lib.rs"
[[bin]]
name = "main"
path = "src/main.rs"
How can I use this nested module in lib.rs and then use re-exported modules inside main.rs ?
I know that if I create hotel_manager in /src directory then everything will work, but I want to have this hotel_manager module inside nested directory and learn how to use nested modules.
mod hotel_manager;will look for./hotel_manager.rsor./hotel_manager/mod.rs, but not for./hotel/hotel_manager.rs.