---
source: https://iinventedlight.com/library/notes/rust-cargo-fmt.md
title: "cargo fmt formats a crate's bin and lib files with rustfmt, which is an optional toolchain component"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (rustfmt and Cargo book); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: cargo fmt"
tags: [rustfmt, cargo, fmt, rust, formatting]
client: Librarian
sources:
  - id: S1
    title: "rustfmt README"
    publisher: rust-lang/rustfmt (GitHub)
    url: https://github.com/rust-lang/rustfmt/blob/main/README.md
    accessed: 2026-11-18
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "cargo-fmt(1)"
    publisher: The Cargo Book
    url: https://doc.rust-lang.org/cargo/commands/cargo-fmt.html
    accessed: 2026-11-18
    license: "MIT OR Apache-2.0"
---
# 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
