My rustfmt Settings
First Off...
rustfmt is a tool to format
There's a ton of info on that page about the tool. None of it is about configuration. You gotta go to the Configuring Rustfmt page to get those details.
Everything, Or Not
You can make a global config file for rustfmt by dropping a file in your home directory at:
~/.rustfmt.toml
Using different options for a specific project is done by putting a .rustfmt.toml
file in the directory that hold your Cargo.toml
file.
It probably makes sense to do that if you do any collaboration with other folks. That way everyone's working with the same settings.
Make It Look Like This
This is what I've set up in my rust formatter file:
fn_params_layout = "Vertical"
max_width = 56
newline_style = "Unix"
tab_spaces = 2
More To Come
There's some other cool stuff working its way into the formatter. These are currently unstable
. Once they move into the stable
branch I'll be playing around with these:
brace_style = "PreferSameLine"
empty_item_single_line = false
enum_discrim_align_threshold = 20
force_multiline_blocks = true
There's also specific style guides. Probably makes sense to look at those for collaborative efforts. Takes the conflicts from differing opinions out of the mix.
-a
Endnotes
You can also name the config files without that dot:
rustfmt.toml
Instead of with it:
.rustfmt.toml