A crate is the smallest amount of code the Rust compiler considers at a time, and it comes in two forms: a binary crate compiles to an executable and must have a main function, while a library crate has no main and defines functionality meant to be shared across projects — most of the time when Rustaceans say crate, they mean a library. The crate root is the source file the compiler starts from, and it makes up the root module of the crate. A package is a bundle of one or more crates described by a Cargo.toml; it must contain at least one crate, may hold as many binary crates as you like, but at most one library crate. cargo new creates a package with a Cargo.toml and src/main.rs, which Cargo treats by convention as the crate root of a binary crate named after the package; a src/lib.rs likewise means a library crate, and extra files under src/bin each become separate binary crates. Cargo passes the crate root files to rustc to build the library or binary. Scope: Rust. Reviewed October 4, 2026.
Packages, crates, and modules
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- doc.rust-lang.org
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.