How to include files from same directory in a module using Cargo/Rust?

All of your top level module declarations should go in, like so:

mod mod1;
mod mod2;

fn main() {
    println!("Hello, world!");

You can then use crate::mod2 inside mod1:

use crate::mod2;

pub fn mod1fn() {

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.

Leave a Comment