You can configure rustfmt a little bit by adding a rustfmt.toml file to your project. The full list of configuration options are on the rustfmt homepage, but these are my preferences:
This is the latest edition of Rust. If you have a
cargo.toml, rustfmt will read the edition from there, but sometimes I'm using rustfmt outside of a cargo project, and in that case it's important to configure it to use the right parser.
I'm a big user of the two-pane view in VSCode, mostly for looking at diffs. That makes it inconvenient to have long lines, so I set
max_width = 80. The other three options here make sure that nothing slips through. (By default, comments and strings are allowed to extend past the 80-character limit.)
group_imports = "StdExternalCrate"requires nightly, but it's so worth it. It organizes your imports so
Crate, as you'd expect.
imports_granularity = "Crate"makes rustfmt group imports by crate.
This automatically uses the
..syntax when destructuring a tuple if you have multiple wildcards at the end. (Think
let (lorem, ipsum, ..) = (1, 2, 3, 4);.) This happens a lot when writing Bevy code and I think it looks cleaner.