I'm having trouble trying to get Rust to load files in subdirectories. Rust treats the files as the modules and the code as part of the module, but I'm used to Ruby's way of treating files and directories separate from the code that they contain.
src/main.rs
mod lib {
pub mod manifest;
}
src/lib/manifest.rs
mod structs {
pub mod entity;
}
src/lib/structs/entity.rs
pub struct entity {
type: String
}
The error I get is:
error: cannot declare a new module at this location
--> src/lib/manifest.rs:2:13
|
2 | pub mod entity;
| ^^^^^^
|
note: maybe move this module `structs` to its own directory via `structs/mod.rs`
--> src/lib/manifest.rs:2:13
|
2 | pub mod entity;
| ^^^^^^
note: ... or maybe `use` the module `entity` instead of possibly redeclaring it
--> src/lib/manifest.rs:2:13
|
2 | pub mod entity;
| ^^^^^^
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…