I have a Cargo project consisting of three files in the same directory: main.rs
, mod1.rs
and mod2.rs
.
I want to import funct
All of your top level module declarations should go in main.rs
, like so:
mod mod1;
mod mod2;
fn main() {
println!("Hello, world!");
mod1::mod1fn();
}
You can then use crate::mod2
inside mod1
:
use crate::mod2;
pub fn mod1fn() {
println!("1");
mod2::mod2fn();
}
I'd recommend reading the chapter on modules in the new version of the Rust book if you haven't already - they can be a little confusing for people who are new to the language.