I created a Rust binary project with cargo new --bin, and ended up with multiple source files.
However, Coursera only accepts single source file solutions.
How can I bundle all project files into one main.rs file?
I created a Rust binary project with cargo new --bin, and ended up with multiple source files.
However, Coursera only accepts single source file solutions.
How can I bundle all project files into one main.rs file?
In Rust, every file is a module. But that doesn't mean that every module needs its own file.
I created a Rust binary project with
cargo new --bin, and ended up with multiple source files.
cargo new --bin creates only one source file, src/main.rs. If you created some other .rs file, you must have put a mod declaration so you could use it inside main.rs:
// main.rs
mod foobar;
use foobar::Foo;
// foobar.rs
struct Foo {}
But instead of creating a separate file, you can put the contents directly in main.rs by changing the mod line:
// main.rs
mod foobar {
struct Foo {}
}
use foobar::Foo; // works exactly the same