How to split modules across files

Split Rust modules across files by creating a new file and declaring it with the `mod` keyword in the parent file.

Split modules across files by creating a new file for the module and declaring it with mod in the parent file.

  1. Create a new file named my_module.rs in the same directory as your main.rs.
  2. Add mod my_module; to your main.rs to declare the module.
  3. Define your items inside my_module.rs and access them using my_module::item_name in main.rs.
// main.rs
mod my_module;

fn main() {
    my_module::greet();
}

// my_module.rs
pub fn greet() {
    println!("Hello from a separate file!");
}