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

Viewed 358

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.

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

Related