rustfmt
rust-lang.github.io
- Free plan
- Windows
- macOS
- Linux
What rustfmt is
rustfmt is a free, open-source formatter for Rust code that applies style guidelines to files or code supplied through standard input. The `cargo fmt` command formats a crate’s binary and library targets and works with Cargo workspaces. For automated checks, `--check` reports whether formatting changes are needed; it exits with code 0 when none are needed and 1 when it would make changes. Configuration goes in `rustfmt.toml` or `.rustfmt.toml`, with stable and nightly-only options. Rustfmt can be run from editors including Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, IntelliJ, and CLion. It is available for Windows, macOS, and Linux and is distributed under the MIT License and Apache License 2.0. Some limitations matter: rustfmt does not attempt to format comments, and its listed limitations include macros, unparsable code, code fragments, and non-ASCII Unicode. Unstable settings require opt-in on a nightly toolchain; the README says the latest version requires nightly.
Who it suits
Rust developers can use rustfmt to apply consistent formatting to files, Cargo projects, and workspaces. It also suits teams that want formatting checks in CI or access to rustfmt from a listed editor.
Good to know, and what to watch
- Formats Cargo crates and workspaces.
- Check mode reports formatting differences with an exit code.
- Configuration files support formatting options.
- Editor integrations include Visual Studio Code and CLion.
- Does not attempt to format comments.
- Unstable settings require nightly and opt-in.
- Listed limitations include macros and non-ASCII Unicode.
Plans
Every plan and pricerustfmt
Open source
The verdict
rustfmt covers formatting from the command line, Cargo, and several editors, with a check mode for CI. Review its limitations and toolchain requirements if your workflow depends on comments, macros, or unstable settings.
What the maker publishes
- Cargo
- The `cargo fmt` command formats all binary and library targets in a crate and works with Cargo workspaces. source
- Cargo
- The `cargo fmt` command formats binary and library targets in a crate and works with Cargo workspaces. source
- Check mode
- With `--check`, rustfmt exits with code 0 when no formatting changes are needed and 1 when changes would be made. source
- CI
- The README describes using `cargo fmt --all -- --check` to fail a CI build when code is not formatted. source
- CI use
- The README describes using `--check` in CI to report formatting differences through an error code. source
- Configuration
- Rustfmt accepts configuration in `rustfmt.toml` or `.rustfmt.toml`, with stable and nightly-only unstable options. source
- Configuration
- Configuration can be set in `rustfmt.toml` or `.rustfmt.toml`, and the default style conforms to the Rust style guide. source
- Direct use
- The rustfmt binary formats files in place or reads Rust code from standard input and writes formatted code to standard output. source
- Editor integrations
- The README lists Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, IntelliJ, and CLion for running rustfmt from an editor. source
- Editor integrations
- The README lists integrations or usage instructions for Vim, Emacs, Sublime Text 3, Atom, Visual Studio Code, and IntelliJ or CLion. source
- Input and output
- The rustfmt binary can format files or read Rust code from standard input and write formatted output to standard output. source
- Install
- The README says to install rustfmt on the stable toolchain with `rustup component add rustfmt`. source
- Install
- The README installs rustfmt as a component through rustup. source
- IntelliJ and CLion
- The IntelliJ and CLion instructions describe enabling rustfmt on save or assigning a shortcut to reformat a file. source
- License
- Rustfmt is distributed under both the MIT License and Apache License 2.0. source
- License
- rustfmt is distributed under both the MIT License and Apache License 2.0. source
- Limitations
- The README lists limitations involving unparsable code, macros, comments, code fragments, non-ASCII Unicode, and bugs. source
- Limit: comments
- Rustfmt does not currently attempt to format comments, though it formats code that contains comments. source
- Limit: macros
- The README says some macro declarations and uses are formatted, while macro declarations and uses are listed among rustfmt’s limitations. source
- Nightly options
- Unstable configuration options are available only on a nightly toolchain and require opt-in. source
- Nightly options
- The README marks coverage, checkstyle, and JSON emit formats as nightly-only options. source
- Purpose
- Rustfmt formats Rust code according to style guidelines. source
- Purpose
- rustfmt formats Rust code according to style guidelines. source
- Security contact
- The Rust Security Response Working Group handles vulnerability reports and security issues for rust-lang organization repositories. source
Checked against the maker's pages on 3 Oct 2026.