diff options
| author | Giang Nguyen <nguyengiangdev@gmail.com> | 2017-01-16 16:24:30 +0700 |
|---|---|---|
| committer | Son <leson.phung@gmail.com> | 2017-02-02 22:19:24 +1100 |
| commit | 3388855443ccfdce427dbbbf8c3d7c3c78bd7b81 (patch) | |
| tree | 85586952f6ad793a7e797f47ea4a98c7c2a8adef /src/doc | |
| parent | 897029d07273315db8bfb734d5e06abcd79f26c3 (diff) | |
| download | rust-3388855443ccfdce427dbbbf8c3d7c3c78bd7b81.tar.gz rust-3388855443ccfdce427dbbbf8c3d7c3c78bd7b81.zip | |
Add explain struct field init shorthand
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/reference.md | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md index dfdfe328820..32e0f9bbed8 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2757,6 +2757,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 |
