Answer the question
In order to leave comments, you need to log in
How to compile multiple files together in Rust?
You can include the file as a module in the file:
//main.rs
mod other_file; // other_file.rs
use other_file::*;
Answer the question
In order to leave comments, you need to log in
Or I did not understand the question or there is something strange.
Rust "compiles together" in its entirety crate (and the Rustbook says so). If entities from one file could not be used in another, then how could such a language be used at all?
Well, "everything works for me." The project structure is as follows:
├── Cargo.lock
├── Cargo.toml
├── src
│ ├── first
│ │ └── mod.rs
│ ├── main.rs
│ └── second.rs
pub fn foo() {
println!("first::foo()");
}
pub fn bar() {
println!("second::bar()");
}
mod first;
mod second;
use second::*;
fn main() {
first::foo();
bar();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question