How many crates a package can contain

according to the documentation - Packages and Crates - The Rust Programming Language

"A package can contain as many binary crates as you like, but at most only one library crate"

I have a binary package whose Cargo.toml contains the following:

name= "alu"
version = "0.1.0"
edition = "2021"

rand = "0.8.5"
image = "0.24.5"

According to the above , the following questions came up :

  1. is the package above is a bundle of one binary crate and two library crates ?

rand and image are dependencies, not crates that belong to the package you have.

if they were belonging , how the *.toml would look like?
Can you proivde with an example of a *.toml file that has one binary crate and one library crate ?

You don't have to add anything to have a binary and a library, just add and files.

The Manifest Format - The Cargo Book <- list of all the things you can put in Cargo.toml file.

1 Like
[lib] # <- referring to the `lib` crate of this package
name = "foo"
path = "src/"

[[bin]] # <- a binary crate
name = "bar"
path = "src/bar/"

[[bin]] # <- another binary crate
name = "baz"
path = "src/baz/"

[[example]] # <- an `example` binary crate
name = "quux"
path = "examples/"

[[test]] # <- an (integration) `test` binary crate
name = "owo"
path = "tests/"

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.