Add explain struct field init shorthand

This commit is contained in:
Giang Nguyen 2017-01-16 16:24:30 +07:00 committed by Manish Goregaokar
parent 3d4f876eb5
commit 0f8a53bfe1
1 changed files with 13 additions and 0 deletions

View File

@ -2765,6 +2765,19 @@ let base = Point3d {x: 1, y: 2, z: 3};
Point3d {y: 0, z: 10, .. base};
```
#### Struct field init shorthand
When initializing a data structure (struct, enum, union) with named fields, allow writing `fieldname` as a shorthand for `fieldname: fieldname`. This allows a compact syntax for initialization, with less duplication.
In the initializer for a `struct` with named fields, a `union` with named fields, or an enum variant with named fields, accept an identifier `field` as a shorthand for `field: field`.
Example:
```
let a = SomeStruct { field1, field2: expression, field3 };
let b = SomeStruct { field1: field1, field2: expression, field3: field3 };
```
### Block expressions
A _block expression_ is similar to a module in terms of the declarations that