Rustfmt
Rustfmt is a formatting tool that enforces the standard Rust-community code style. By default, Rustfmt is disabled. You can enable it, in which case the IDE will use Rustfmt instead of the built-in formatter when formatting Rust files and projects.
Enable (or disable) Rustfmt instead of the built-in formatter
Open settings by pressing Control+Alt+S and navigate to
To enable Rustfmt, set the Use rustfmt instead of built-in formatter checkbox. To disable Rustfmt, clear the checkbox.
Click OK to apply the changes.
Automatically run Rustfmt on Save
You can configure RustRover to run Rustfmt for Rust files whenever they are saved:
Open settings by pressing Control+Alt+S and navigate to
.Set the Run rustfmt on Save checkbox.
Click OK to apply the change.
Configure Rustfmt calls
Open settings by pressing Control+Alt+S and navigate to
.If necessary, specify additional arguments for Rustfmt. All available options are listed in Rustfmt docs. Make sure to add
--unstable-features
if you use unstable options.Select the preferred Rustfmt channel (stable, beta, nightly, or dev) or let the IDE use the default one.
Set custom environment variables if needed.
If you want to make Rustfmt the default formatter, select Use rustfmt instead of built-in formatter. For more information, refer to Enable (or disable) Rustfmt instead of the built-in formatter.
Set the Run rustfmt on Save checkbox if you want RustRover to reformat Rust files automatically whenever it saves changes. For more information, refer to Automatically run Rustfmt on Save.
Click OK to apply the changes
Formatting with Rustfmt
You can run Rustfmt manually – for a particular file or Cargo project.
Reformat a file with Rustfmt
Open the file you'd like to reformat.
Press Control+Alt+Shift+L or select
from the main menu.In the
dialog, select the necessary scope. You can also select additional options:Optimize imports: select this option if you want to remove unused imports, add missing ones, or organize import statements.
Code cleanup: select this option to run the code cleanup inspections.
Do not keep line breaks: reformat line breaks according to the code style settings. This option overrides the setting.
Click
.
Reformat all files in the current Cargo project
Open the project you'd like to reformat. Do one of the following:
Go to
.Open any Rust file in the editor, right-click, and select
to open the context menu.