Trying to get Rust to load files -
i'm having trouble trying rust load files in subdirectories. rust treats files modules , code part of module, i'm used ruby's way of treating files , directories separate code 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 is:
error: cannot declare new module @ location --> src/lib/manifest.rs:2:13 | 2 | pub mod entity; | ^^^^^^ | note: maybe move module `structs` own directory via `structs/mod.rs` --> src/lib/manifest.rs:2:13 | 2 | pub mod entity; | ^^^^^^ note: ... or maybe `use` module `entity` instead of possibly redeclaring --> src/lib/manifest.rs:2:13 | 2 | pub mod entity; | ^^^^^^
the best way fix rename manifest file mod.rs , change first line in main.rs to:
mod lib;
and change mod.rs to:
pub mod structs { mod entity; }
i think reason error because there's manifest.rs file no folder. why causes subfolder files not load can't say, i'm still new rust myself there's chance i'm wrong.
someone more rust knowledge might know, since they're downvoting instead of being helpful, doubt you'd better answer.
Comments
Post a Comment