Dependent files in same project

Problem I'm having is to include module_a into module_b. Asking chatgpt it gave this solution

my_project/
│── src/
│ │── main.rs (Entry point)
│ │── module_a.rs (Contains functions and structs)
│ │── module_b.rs (Depends on module_a)
│── Cargo.toml

// src/module_a.rs
pub struct Data {
pub value: i32,
}

pub fn show_data(data: &Data) {
println!("Data value: {}", data.value);
}

// src/module_b.rs
use crate::module_a::Data; // Correct way to import from module_a

pub fn process_data() -> Data {
Data { value: 42 }
}

Well, it doesn't work. Keep getting "Could not find module_a in crate root."

Every module must be declared, which is a separate matter from where it is used. main.rs must contain:

mod module_a;
mod module_b;
1 Like

The doc is more accurate:
https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html#modules-cheat-sheet