rust: reformat imports and max width
I am proposing a change to our rustfmt.toml, made in two commits:
- Use imports_granularity = "Item" and group_imports = "StdExternalCrate". This is +563 LOC.
- Use max_width = 80 and use_small_heuristics = "Max". This is -940 LOC.
For context, we have about 45K non-blank lines of Rust.
There are a few options for imports_granularity: Item, Module, Crate, One. It's debatable which is best, but I think everyone will agree choosing something is better than leaving them all formatted differently. "Item" uses up the most lines but causes the fewest merge conflicts. See https://issues.fuchsia.dev/issues/340943530#comment2 for an argument in favor of "Module".
"StdExternalCrate" arranges imports in three groups: std/core, external crates, and the current crate.
I'm not sure why max_width was 79. I'd personally be in favor of the rustfmt default (100), but failing that using the same value as we do for Python (80) makes more sense to me.
The "small heuristics" cause rustfmt to actually prefer a much smaller line length for various constructs. For example, it will split a struct literal on multiple lines after exceeding only 18% of max_width. The "Max" value disables this and allows it to use the full 80 columns for everything. I dislike the small heuristics because it led me to define intermediate variables purely to avoid something being split up over many lines.