Crates: compilation units in Rust, binary or library
A crate is a compilation unit in Rust:
- Whenever
rustc some_file.rsis called,some_file.rsis treated as the crate file. - If
some_file.rshasmoddeclarations in it, then the contents of the module files would be inserted in places wheremoddeclarations in the crate file are found, 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,
rustcwill produce a binary from a crate. - This behavior can be overridden by passing the
--crate-typeflag tolib.