Import modules in local crates

I'm trying to understand how to import modules. Rust By Example only covers the most common cases, and is not clear what to do in other cases - or if other cases are the results of bad design.

So, my questions are:

  • How do I import src/common/b.rs into src/common/a.rs?
  • Is it a bad idea to do so?
  • How do I import src/hello/hello.rs into src/world/world.rs?
  • Is it a bad idea to do so?

/src/common/mod.rs

mod a;
mod b;

/src/common/a.rs

use super::b; // relative import
use crate::common::b; // absolute import

use crate::hello::hello;
2 Likes

And no, neither are a bad idea.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.