Rust by Example

10 Crates

A crate is a compilation unit in Rust. Whenever rustc is called, is treated as the crate file. If has mod declarations in it, then the contents of the module files will get merged with the crate file before running the compiler over it. In other words, modules do not get compiled individually, only crates get compiled.

A crate can be compiled into a binary or into a library. By default, rustc will produce a binary from a crate. This behavior can be overridden by passing the --crate-type flag to rustc.