10

I have the file structure: engine and utils folder on same level. Engine contains world folder (which contains mod.rs and map.rs) and mod.rs. Utils contains mod.rs and reader.rs.

I'm trying to access map from reader but cannot get the 'use' statement to work.

utils/mod.rs

pub mod reader;

engine/mod.rs

pub mod world;

world/mod.rs

pub mod map;

pub struct World;

I get this error:

error[E0433]: failed to resolve. Maybe a missing `extern crate engine;`?
 --> src\utils\reader.rs:5:5
  |
5 | use engine::world::map;
  |     ^^^^^^ Maybe a missing `extern crate engine;`?

Can you not declare modules inside of subdirectories, or am I missing something stupid? I've been messing about with use statements for about half an hour now and can't get it to work.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
James Mclaughlin
  • 570
  • 1
  • 8
  • 16
  • Where's the file with `mod engine`? – Shepmaster Aug 30 '18 at 23:52
  • I believe your question is answered by the answers of [How to use one module from another module in a Rust cargo project?](https://stackoverflow.com/q/48071513/155423). If you disagree, please [edit] your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Aug 30 '18 at 23:53
  • See also [How does the import/module system in Rust work?](https://stackoverflow.com/q/44073359/155423); [How to include module from another file from the same project?](https://stackoverflow.com/q/26388861/155423); [How do you use parent module imports in Rust?](https://stackoverflow.com/q/20922091/155423); [Access submodule from another submodule when both submodules are in the same main module](https://stackoverflow.com/q/30670129/155423); or really [anything in the tag with the word "module"](https://www.google.com/search?q=site:stackoverflow.com%20rust%20module) – Shepmaster Aug 30 '18 at 23:55
  • 1
    I also recommend re-reading the **official, high-quality, and free** book [*The Rust Programming Language*](https://doc.rust-lang.org/book/second-edition/), specifically [`mod` and the Filesystem](https://doc.rust-lang.org/book/second-edition/ch07-01-mod-and-the-filesystem.html). – Shepmaster Aug 30 '18 at 23:57
  • I believe the question is about having source files in subfolders. So their file structure must be /src/engine/world/map.rs – ikamen Oct 11 '19 at 14:00

0 Answers0