How to import a module from another file in the same Rust project?
Hi everyone! I just started learning Rust and encountered a problem with code organization. My project is growing quickly, and I want to split it into multiple files, but I don't understand how to properly import functions and structures from one file to another.
Here is my current structure. I have `main.rs` and I created a file `math_utils.rs` in the same `src/` folder. In `math_utils.rs` I defined a simple function:
```rust
// math_utils.rs
fn add(x: i32, y: i32) -> i32 {
x + y
}
```
And in `main.rs` I'm trying to call it:
```rust
// main.rs
fn main() {
let result = add(5, 3); // Error: cannot find function `add` in this scope
println!("Result: {}", result);
}
```
I tried adding `mod math_utils;` at the beginning of `main.rs`, but it didn't help. The compiler gives an error that the modul
No answers yet.
Log in to leave an answer