cargo fmt formats a crate's bin and lib files with rustfmt, which is an optional toolchain component
Answer: cargo fmt formats the bin and lib files of the current crate using rustfmt. It is an external command distributed with the Rust toolchain as an optional component, not built into Cargo itself. Install the rustfmt component, then run cargo fmt in the package.
What cargo-fmt is
The Cargo Book man page names the command cargo-fmt and says it formats all bin and lib files of the current crate using rustfmt. It may require additional installation because it is not built into Cargo.
Claims
- id: C1 claim: rustfmt is the Rust code formatter invoked by cargo fmt. source: S1 evidence: "rustfmt"
- id: C2 claim: The rustfmt project documents installation and usage. source: S1 evidence: "cargo fmt"
- id: C3 claim: cargo fmt formats the crate's bin and lib files with rustfmt. source: S2 evidence: "Formats all bin and lib files of the current crate using rustfmt"
- id: C4 claim: cargo-fmt is not built into Cargo and may need installation. source: S2 evidence: "It is not built into Cargo"
Sources
- [S1] rustfmt README. rust-lang/rustfmt (GitHub). https://github.com/rust-lang/rustfmt/blob/main/README.md . License: MIT OR Apache-2.0. Accessed 2026-11-18.
- [S2] cargo-fmt(1). The Cargo Book. https://doc.rust-lang.org/cargo/commands/cargo-fmt.html . License: MIT OR Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: rust-lang/rustfmt (GitHub), rustfmt README, MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rustfmt/main/LICENSE-MIT); The Cargo Book, cargo-fmt(1), MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-MIT). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: rust-lang/rustfmt (GitHub), rustfmt README, MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/rustfmt/main/LICENSE-MIT); The Cargo Book, cargo-fmt(1), MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-MIT).
Cite this
iinventedlight. 2026. "cargo fmt formats a crate's bin and lib files with rustfmt, which is an optional toolchain component." iinventedlight Library, iil:note:30e542h6, version of 2026-11-18. https://iinventedlight.com/library/notes/rust-cargo-fmt/. License: CC-BY-4.0.
@misc{iil_note_30e542h6,
author = {{iinventedlight}},
title = {{cargo fmt formats a crate's bin and lib files with rustfmt, which is an optional toolchain component}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/rust-cargo-fmt/},
note = {Permanent ID iil:note:30e542h6. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/rust-cargo-fmt.md.