How can I include a module from another file from the same project?
@lebyy▲ 0 net votes
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…