- Home
- Code Formatting Tools
- rustfmt
rustfmt
What it is
rustfmt formats Rust code according to style guidelines, either in files or from standard input to standard output. For Cargo projects, `cargo fmt` formats binary and library targets and works across workspaces. Install it on the stable toolchain with `rustup component add rustfmt`. Configuration goes in `rustfmt.toml` or `.rustfmt.toml`; additional unstable settings require opt-in on a nightly toolchain. The `--check` option reports whether formatting changes are needed, making it useful in CI. Rustfmt can be run from Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, IntelliJ, and CLion. It is free and open source, supports Linux, macOS, and Windows, and is distributed under the MIT License and Apache License 2.0. It does not attempt to format comments, and its listed limitations include macros, unparsable code, code fragments, and non-ASCII Unicode. The README says rustfmt runs with Rust 1.24 and above, while the latest version requires the nightly toolchain.
For and against
For
- Formats Cargo targets across workspaces.
- Reads code from standard input and writes formatted output.
- Supports configuration files and editor integrations.
- Can report formatting differences in CI.
- Free and open source.
Against
- Does not attempt to format comments.
- Some macro cases are listed as limitations.
- Unstable settings require nightly and opt-in.
- The latest version requires nightly.
The verdict
rustfmt covers common Rust formatting workflows, from direct file use to Cargo and editor integrations. Its documented limits around comments, macros, and nightly-only options are worth considering.
Who it suits
Rust developers who want consistent formatting in files, Cargo projects, or editor workflows may find rustfmt useful. It also suits teams that want a formatting check in CI.
Plans and prices
rustfmt
No paid plans stated
Read 3 Oct 2026 · github.com
On the record
- Cargo
- The `cargo fmt` command formats binary and library targets in a crate and works with Cargo workspaces.github.com · read 3 Oct 2026
- Check mode
- With `--check`, rustfmt exits with code 0 when no formatting changes are needed and 1 when changes would be made.github.com · read 3 Oct 2026
- CI
- The README describes using `cargo fmt --all -- --check` to fail a CI build when code is not formatted.github.com · read 3 Oct 2026
- CI use
- The README describes using `--check` in CI to report formatting differences through an error code.github.com · read 2 Oct 2026
- Configuration
- Configuration can be set in `rustfmt.toml` or `.rustfmt.toml`, and the default style conforms to the Rust style guide.github.com · read 3 Oct 2026
- Direct use
- The rustfmt binary formats files in place or reads Rust code from standard input and writes formatted code to standard output.github.com · read 3 Oct 2026
- Editor integrations
- The README lists integrations or usage instructions for Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, and IntelliJ or CLion.github.com · read 3 Oct 2026
- Input and output
- The rustfmt binary can format files or read Rust code from standard input and write formatted output to standard output.github.com · read 2 Oct 2026
- Install
- The README installs rustfmt as a component through rustup.github.com · read 3 Oct 2026
- IntelliJ and CLion
- The IntelliJ and CLion instructions describe enabling rustfmt on save or assigning a shortcut to reformat a file.github.com · read 3 Oct 2026
- License
- rustfmt is distributed under both the MIT License and Apache License 2.0.github.com · read 3 Oct 2026
- Limitations
- The README lists limitations involving unparsable code, macros, comments, code fragments, non-ASCII Unicode, and bugs.github.com · read 3 Oct 2026
- Limit: comments
- Rustfmt does not currently attempt to format comments, though it formats code that contains comments.github.com · read 2 Oct 2026
- Limit: macros
- The README says some macro declarations and uses are formatted, while macro declarations and uses are listed among rustfmt’s limitations.github.com · read 2 Oct 2026
- Nightly options
- The README marks coverage, checkstyle, and JSON emit formats as nightly-only options.github.com · read 3 Oct 2026
- Purpose
- rustfmt formats Rust code according to style guidelines.github.com · read 3 Oct 2026
- Security contact
- The Rust Security Response Working Group handles vulnerability reports and security issues for rust-lang organization repositories.github.com · read 2 Oct 2026
- Style stability
- The Rust Edition Guide describes a formatting stability guarantee intended to avoid noisy formatting changes when updating the Rust toolchain.doc.rust-lang.org · read 2 Oct 2026