← All notes

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

Sources

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

Permanent ID: iil:note:30e542h6

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.},
}

Markdown

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.