Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use the --bin option for cargo new?

What is the difference between cargo new <project_name> --bin and cargo new <project_name>?

It seems both commands make exactly the same project; all components are consistent.

I think --bin stands for "binary", but I don't know when to use this option or not.

like image 678
kwklly Avatar asked Sep 16 '25 21:09

kwklly


1 Answers

There is no difference between cargo new and cargo new --bin. From First Steps with Cargo, emphasis mine:

To start a new package with Cargo, use cargo new:

$ cargo new hello_world

Cargo defaults to --bin to make a binary program. To make a library, we would pass --lib, instead.

Likewise, Cargo's command line help tells you the same thing. From cargo new --help, with some irrelevant lines removed:

% cargo new --help
OPTIONS:
        --bin                      Use a binary (application) template [default]
        --lib                      Use a library template

See also

  • Why does `cargo new` create a binary instead of a library?
  • What is the difference between library crates and normal crates in Rust?
like image 193
Shepmaster Avatar answered Sep 19 '25 08:09

Shepmaster