How do I run src/main.rs by default with cargo run?

Sorry for the rudimentary question.
When I run cargo run I get the following output.

āÆ cargo run
error: `cargo run` could not determine which binary to run. Use the `--bin` option to specify a binary, or the `default-run` manifest key.
Available binaries: async_await_basic, asynchronous, thread_and_async

I am instructed to specify the bin directory, but I want to run src/main.rs, so I investigated if the module structure is bad, but there is no module conflict.

Directory structure

perfect-rust/practice_collection/thread_and_async on ī‚  develop [!?] via šŸ¦€ v1.72.0 
āžœ tree
.
ā”œā”€ā”€ Cargo.toml
README.md
ā””ā”€ā”€ src
    ā”œā”€ā”€ basic.rs
    ā”œā”€ā”€ bin
    ā”‚ ā”œā”€ā”€ async_await_basic.rs
    ā”‚ ā””ā”€ asynchronous.rs
    ā”œā”€ cross_beam.rs
    ā”œā”€ā”€ exclusive_mutex.rs
    ā”œā”€ā”€ exclusive_rwlock.rs
    ā”œā”€ā”€ exclusive_shradelock.rs
    ā”œā”€ā”€ lib.rs
    ā”œā”€ā”€ main.rs
    ā”œā”€ messaging_crossbeam.rs
    ā”œā”€ messaging_std.rs
    ā””ā”€ task
        ā”œā”€ client.rs
        ā”œā”€ā”€ customer.rs
        ā”œā”€ā”€ mod.rs
        ā”œā”€ task_controller.rs
        ā””ā”€ writer.rs

If I set the default-run key in the Cargo.toml file to thread_and_sync, the cargo run works as expected.
I just don't understand why I have to set default-run to the above.

I am sorry, but could you please enlighten me on this point?

That's the answer to the question in your subject.[1]

You mean, why was it designed this way? Seems to be just how things happened. That issue is pretty old; not sure if making main.rs or name-of-package.rs the effectively default default-run has been discussed since then or not.


  1. I'm assuming you mean thread_and_async, i.e. the name of the package. ā†©ļøŽ

1 Like

Thank you very much for your help due to my lack of knowledge, I have read the entire ISSUE and understand how this issue was resolved.
Thank you very much for your reply.