Forrest logo
tool overview
On this page you find all important commands for the CLI tool rustfmt. If the command you are looking for is missing please ask our AI.

rustfmt

Rustfmt is a command line tool for formatting Rust code in a consistent and aesthetically pleasing manner. It is designed to automatically apply a set of predefined style rules to your Rust code files.

This tool is written in Rust itself and can be installed via Cargo, the Rust package manager. Once installed, you can run rustfmt on your codebase to automatically format all Rust source files according to the defined style rules.

Rustfmt is designed to enforce the official Rust style guidelines, making it easier for developers to follow a consistent and readable coding style across projects. It can handle a variety of formatting tasks, including indentation, line length, spacing, and more.

The main advantage of Rustfmt is that it eliminates the need for manual formatting, saving time and effort while maintaining a clean codebase. It enforces formatting consistency within a team, reducing unnecessary changes during code reviews and avoiding style-related discussions.

Rustfmt also provides additional configuration options, allowing developers to customize the formatting rules according to their preferences. The tool supports integration with popular code editors through plugins, enabling automatic formatting on save or through keyboard shortcuts.

However, it is worth noting that Rustfmt may introduce changes to your codebase when formatting, so it is advisable to version control your code before running the tool. This allows you to review and revert any unintentional changes.

Overall, Rustfmt is a valuable tool for Rust developers, ensuring code readability, maintainability, and adherence to the community's accepted style guidelines.

List of commands for rustfmt:

  • rustfmt:tldr:30088 rustfmt: Check a file for formatting and display any changes on the console.
    $ rustfmt --check ${path-to-source-rs}
    try on your machine
    explain this command
  • rustfmt:tldr:9f5d6 rustfmt: Format a file, overwriting the original file in-place.
    $ rustfmt ${path-to-source-rs}
    try on your machine
    explain this command
  • rustfmt:tldr:c89df rustfmt: Backup any modified files before formatting (the original file is renamed with a `.bk` extension).
    $ rustfmt --backup ${path-to-source-rs}
    try on your machine
    explain this command
tool overview