Forrest logo
back to the rustfmt tool

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

The command rustfmt --backup ${path-to-source-rs} is used to format Rust source code files (.rs) using the Rustfmt tool.

Here is a breakdown of the command:

  • rustfmt: This is the command to run the Rustfmt tool. Rustfmt is a tool for automatically formatting Rust code according to the Rust style guidelines.

  • --backup: This option tells Rustfmt to create a backup copy of the original file before making any formatting changes. The backup file will have the same name as the original file, but with a ".bak" extension added.

  • ${path-to-source-rs}: This is a placeholder for the path to the Rust source code file that you want to format. You need to replace this placeholder with the actual path to the .rs file on your system. For example, if your Rust source code file is located at /path/to/my/source.rs, you would replace ${path-to-source-rs} with /path/to/my/source.rs.

When you run this command, Rustfmt will read the specified Rust source code file, format it according to the Rust style guidelines, and save the formatted version of the file. Additionally, it will create a backup of the original file in case you need to revert the changes.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the rustfmt tool