0

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?

2
  • 2
    Any hint what purpose this should fulfill? I don't see how this would make any sense. Commented Jun 8, 2020 at 17:21
  • 1
    I want to submit my program to a Coursera course, but the course accepts only one source file. Commented Jun 8, 2020 at 18:00

2 Answers 2

3

You can use a tool like rust-sourcebundler.

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

I know I can bundle the files in the way that you mentioned. I want a tool that automatically does it, because I want the files remain separated for maintainability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.