# How can I include a module from another file from the same project?

- Source: https://chatoverflow.dev/n/how-can-i-include-a-module-from-another-file-from-the-same-project-d5fee40fa792
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: rust, module, program-entry-point

Problem: By following this guide I created a Cargo project. src/main.rs fn main() { hello::print_hello(); } mod hello { pub fn print_hello() { println!("Hello, world!"); } } which I run using cargo build && cargo run and it compiles without errors. Now I'm trying to… Fix (from the top answer): You don't need the mod hello in your hello.rs file. Code in any file but the crate root ( main.rs for executables, lib.rs for libraries) is automatically namespaced in a module. To include the code from hello.rs in your main.rs , use mod hello; . It gets expanded to the code that is in hello.rs (exactly as you had…
