2018-09-11 23:34:32 +05:30
|
|
|
# rustfmt
|
|
|
|
|
2024-02-14 17:25:13 -03:00
|
|
|
> Format Rust source code.
|
2019-05-23 11:56:50 +01:00
|
|
|
> More information: <https://github.com/rust-lang/rustfmt>.
|
2018-09-11 23:34:32 +05:30
|
|
|
|
|
|
|
- Format a file, overwriting the original file in-place:
|
|
|
|
|
2023-01-04 09:57:33 +05:30
|
|
|
`rustfmt {{path/to/source.rs}}`
|
2018-09-11 23:34:32 +05:30
|
|
|
|
|
|
|
- Check a file for formatting and display any changes on the console:
|
|
|
|
|
2023-01-04 09:57:33 +05:30
|
|
|
`rustfmt --check {{path/to/source.rs}}`
|
2018-09-11 23:34:32 +05:30
|
|
|
|
|
|
|
- Backup any modified files before formatting (the original file is renamed with a `.bk` extension):
|
|
|
|
|
2023-01-04 09:57:33 +05:30
|
|
|
`rustfmt --backup {{path/to/source.rs}}`
|
2025-06-10 21:21:40 +10:00
|
|
|
|
|
|
|
- Format code using a specific Rust style edition (formatting rules) verbosely:
|
|
|
|
|
|
|
|
`rustfmt --style-edition {{2015|2018|2021|2024}} {{[-v|--verbose]}} {{path/to/source1.rs path/to/source2.rs ...}}`
|
|
|
|
|
|
|
|
- Format code using a specific Rust edition (language features and parsing):
|
|
|
|
|
|
|
|
`rustfmt --edition {{2015|2018|2021|2024}} {{path/to/source1.rs path/to/source2.rs ...}}`
|