rustfmt
rustfmt copied to clipboard
[unstable option] space_before_colon
Tracking issue for unstable option: space_before_colon
(Please excuse if this does not belong here)
Is there a way (planned) to distinguish between a parameter list, let statement, and other uses of the type annotation colon?
I would like to have my code formatted so that
let my_string : String = "hello".to_string();
has a space before the colon, because the colon feels like it separates the type from the identifier.
But I would like to have no space before the colon here:
fn foo( my_arg: String, another_arg: &str) {
}
because the type belongs to its preceeding argument and it feels like it is too close to the next parameter when I have the space before the colon.
Of course, tastes may vary. And it's not that important to be able to distinguish these cases. But I'd like to, if it was easily doable.
My thoughts as well, but to say it in one rule: The colon belongs with the type when the type is optional. Because they are added or removed together. Just like in UML.
I can think of 3 uses of colon:
- Before an optional type (those
letstatements) - Before an obligatory type (such as function and struct parameters)
- Before a value (in designated initializers)
I would also remove the space after the colon (#3366) by the exact same rule, but maybe that's just me.
I just think it looks more readable with the space before the colon across the board. ML-heritage showing 😄