Would you mind replying with “+1” if you prefer =
or with “-1” if you prefer the current :
?
Here are my reasons for me liking =
, as copied from my closed RFC:
A =
between the field name and the value in struct expressions just seems a much better fit than :
, given the context of the Rust language and other languages with similar syntax. Before RFC 25, using =
instead of :
wouldn’t have worked, because =
would have created an ambiguity between a struct expression and a block with an assignment, but now the token can be chosen to be whatever seems fit.
In other languages with a similar construct, =
is more widely used.
In OCaml:
type point = {x: int; y: int};;
{ x=3; b=5 };;
In Haskell:
data Point = Pt {x, y :: Float}
Pt {x=3, y=5}
In Python:
Point = namedtuple('Point', 'x y')
Point(x=3, y=5)
In Rust itself, beside struct expressions, the pattern A: B
is used for declaring types and for declaring type boundaries. In both of these cases, A: B
can be read as "A
is a B
", or "A
is a member of the set B
". That is, the more general entity is on the right. This certainly can’t be said of x: 3
.
On the other hand, =
is used mainly for assignments. In let p = Point { x=3, y=5 }
it can certainly be said that p.x
is assigned the value 3
. Another usage of =
is in keyword arguments (Currently in the fmt!
family of macros, perhaps some day in general functions). The use of =
for keyword arguments also aligns well with using =
for struct expressions, since the form Point { x=3, y=5 }
can be seen as a special constructor which accepts a keyword argument for each field.
There are more discussions about this at the closed RFC PR 65.