LinthelmIntroductions to linters, static analysis and code-quality tools

Formatters

What is rustfmt? An introduction to the Rust Project's Rust code formatter

By the Linthelm editorial team · Published · Updated

rustfmt is a tool for formatting Rust code according to style guidelines. It can be run directly, through cargo fmt, or on code read from stdin. Its --check flag makes it suitable for keeping Rust code consistently formatted in CI.

Tool
rustfmt
Made by
Rust Project
Official site
github.com/rust-lang/rustfmt
Category
Formatters

Who makes rustfmt

rustfmt is made by the Rust Project. The official website, which is the project's GitHub repository, is linked below this page.

It is dual-licensed under MIT and Apache 2.0, so users can choose either license.

Official website: github.com/rust-lang/rustfmt

What rustfmt is for

rustfmt rewrites Rust source code so that it follows a consistent set of style guidelines. Its default style follows the Rust style guide, which was formalized through the style RFC process. That gives a project a shared baseline instead of a per-developer habit.

It tries to work on as much Rust code as possible, even code that does not compile. A file that is mid-edit or temporarily broken can therefore still be formatted. When you give it a file that has out-of-line modules, it reformats those modules as well, so one invocation can cover a whole module tree.

Who rustfmt is for

rustfmt is aimed at Rust developers and at teams that want Rust code to stay consistently formatted in CI. Individual developers can run it as they work, while teams can enforce the same formatting on every change.

For CI use, the --check flag makes rustfmt exit with an error code when the input is unformatted. A minimal Travis CI configuration is also provided as a starting point. It can be run with Rust 1.24 and above.

Notable capabilities

rustfmt covers everyday formatting, project-wide runs, CI checks and configuration. The capabilities below are the ones the project documents.

  • cargo fmt formats projects and works on both single crates and cargo workspaces.
  • It can read code from stdin, which allows it to sit behind editors and scripts.
  • The --check flag makes it exit with an error code when input is unformatted, which suits CI checks.
  • It is highly configurable through a rustfmt.toml or .rustfmt.toml file.
  • Configuration options are split into stable and unstable ones, and the unstable ones require nightly.
  • The #[rustfmt::skip] attribute excludes specific code from formatting.
  • The --emit flag lets output be emitted in different ways.
  • It supports args-files using @.

How rustfmt fits formatters

Within the formatters category, rustfmt is the Rust-specific option: it targets one language and follows that language's official style guide. A formatter changes how code is laid out and does not look for bugs, so it answers a different question from a linter.

In the wider world of linters, static analysis and code quality, formatting is the layer that removes style from the conversation. When layout is handled automatically and verified with --check in CI, reviewers and analysis tools can spend their attention on logic, correctness and design instead of whitespace and line breaks.

Frequently asked questions

What is rustfmt used for?

rustfmt is used to format Rust code according to style guidelines. It can be run on files, through cargo fmt on crates and workspaces, or on code read from stdin.

Who develops rustfmt?

rustfmt is made by the Rust Project. It is dual-licensed under MIT and Apache 2.0.

How do I check formatting in CI with rustfmt?

Use the --check flag, which makes rustfmt exit with an error code when the input is unformatted. A minimal Travis CI configuration is also provided.

Can rustfmt format code that does not compile?

rustfmt tries to work on as much Rust code as possible, even code that does not compile. It also reformats out-of-line modules when given a file that contains them.

How do I configure rustfmt?

Add a rustfmt.toml or .rustfmt.toml file. Options are split into stable and unstable ones, and unstable ones require nightly.

Sources. This introduction is based on the vendor's official pages, checked on 21 November 2026 (Asia/Dhaka):

Linthelm is independent and is not affiliated with Rust Project. Product names belong to their owners. Features change; confirm details on the official website.