talira

A tool for formatting Rust code according to style guidelines

open sourceMIT OR Apache-2.0self-hostablefree

rustfmt is the official formatter for Rust code, formatting it to the Rust style guidelines. It ships as a rustup component (rustup component add rustfmt) and runs on a whole project through Cargo with cargo fmt, or on files with rustfmt; --check exits non-zero when code isn't formatted, for CI and pre-commit hooks. A rustfmt.toml file in the project configures options such as line width and import grouping, some of them only on the nightly toolchain. Plugins run it from Vim, Emacs, VS Code and other editors. It's dual-licensed MIT or Apache-2.0.

Problems it solves

  • format Rust code consistently across a team
  • fail CI when a pull request contains unformatted Rust code
  • format a whole Cargo workspace with one command
  • configure line width and import ordering for Rust formatting
  • format Rust on save in my editor

Features

  • formats Rust code to the style guidelines
  • cargo fmt for whole projects and workspaces
  • --check mode for CI
  • rustfmt.toml or .rustfmt.toml configuration
  • stable and nightly toolchain components
  • editor integrations for Vim, Emacs, VS Code and others

Limitations

  • Code that doesn't parse, macro declarations and uses, and comments are formatted only partly or not at all

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what rustfmt does.

  1. Prettier An opinionated code formatter that reprints your code in one consistent style
  2. Ormolu A formatter for Haskell source code

Compare rustfmt with the top 3