1

I am using Rust 2018 with the following file structure:

src/main.rs
src/types.rs
src/compute.rs

types.rs contains pub struct Entity {}.

I have no issue including types and compute in main.rs:

mod types;
mod compute;

I want to import types inside compute.rs:

mod types;
// or
pub mod types;

I get:

file not found for module types 

I tried to follow path clarity in the edition guide without success.

The examples never refer to a same level import that is not from main.rs or lib.rs

I tried to specify the path using:

#[path = "types.rs"] mod types;

Then I get this error:

expected type `compute::types::Entity`
              found type `types::Entity`

It seems it is redefining the module types inside my module compute.

I cannot use the use keyword since it is not an external crate.

I took a look at file hierarchy in Rust by Example but there is no same level import.

I am trying to avoid having mod.rs like in Rust 2015.

  1. Is there a way to do this same level import?

  2. Is my file structure the issue?

  3. What file structure would be better?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Scott
  • 383
  • 3
  • 10
  • *I want to import to types inside compute.rs* — in **addition** to or **instead of** importing `types` in main? – Shepmaster Apr 13 '20 at 15:29
  • Importing types in compute in addition of main – Scott Apr 13 '20 at 15:31
  • It looks like your question might be answered by the answers of [How do I import from a sibling module?](https://stackoverflow.com/q/30677258/155423); [What are the valid path roots in the use keyword?](https://stackoverflow.com/q/54289071/155423). If not, please **[edit]** your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Apr 13 '20 at 15:32
  • TL;DR the duplicates: in *compute.rs*, add `use crate::types::Entity;` – Shepmaster Apr 13 '20 at 15:37
  • Looks like the `use super::types;` did the trick. – Scott Apr 13 '20 at 15:37

0 Answers0