1

how do I import a module from the same parent directory in rust

├── main.rs
└── utils
    ├── circle.rs
    └── ray.rs

how do I import ray.rs from circle.rs

I tried using mod ray; in circle.rs but rust-analyzer is giving me the error unresolved module, can't find module file: circle/ray.rs, or circle/ray/mod.rs

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841

1 Answers1

0

You need to create utils.rs next to main.rs, and then put the following in it.

mod circle;
mod ray;

This also works as utils/mod.rs, but utils.rs is preferred.

Ensure main.rs has mod utils;.

Then in ray.rs you can put one of the following.

use super::circle;

or

use crate::utils::circle;
drewtato
  • 6,783
  • 1
  • 12
  • 17