6
votes

While reading the official book, I stumbled upon packages and crates. To create a new "project", this is what I ran:

$ cargo new my-project
     Created binary (application) `my-project` package
$ ls my-project
Cargo.toml
src
$ ls my-project/src
main.rs

The book states the following:

A package must contain zero or one library crates, and no more. It can contain as many binary crates as you’d like, but it must contain at least one crate (either library or binary).

My doubt is, what is the difference between binary crates and normal crates?

1
Where did you get the idea of "normal" crates? It's not in the book, and you talk about "library and normal" in the title, but "binary and normal" in the question body. - Herohtar
My bad @Herohtar. - Aviral Srivastava

1 Answers

11
votes

The difference is between binary crate and library crate. There are no "normal" crates.

  • A binary crate is an executable program.

  • A library crate is a library of reusable components that can be included in another library crate or in a binary crate.