Using files from the same module in Rust

Viewed 56

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 Answers

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.

Related