2

I have this file structure:

src
├── core
│   ├── game.rs
│   ├── math.rs
│   └── screen.rs
├── core.rs
└── main.rs

Inside of core/screen.rs I have a struct Screen. I can use this struct and its function in main.rs like

mod core;

fn main() {
  let s = core::screen::Screen::new();
}

That works, however the problem is, inside of core/game.rs I can't use that same struct. I've tried use and mod but I can't figure it out. Inside core/game.rs

pub struct Game {
  screen: ?????? // Should be core::screen::Screen?
}

And for those wondering, the contents of core.rs looks like

pub mod math;
pub mod screen;
pub mod game;

Right now the core.rs file doesn't exactly have a use except for a very weird namespace almost but it will have functions in the future.

1
  • 1
    Aside: I'd avoid using core as a module name, to avoid conflict/ambiguity with The Rust Core Library. Commented Feb 2, 2022 at 6:39

1 Answer 1

2

Prepend it with crate:::

// core/game.rs

pub struct Game {
  screen: crate::core::screen::Screen
}

Or throw a use crate::core::screen; at the top of the file and then use screen: screen::Screen.

Sign up to request clarification or add additional context in comments.

2 Comments

super::screen::Screen would also work.
Thanks, I tried using the crate keyword but I was using that in a way such as use crate::core::screen which doesn't work. Using crate worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.