diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-04-21 15:23:14 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-04-21 15:23:14 -0700 |
| commit | ee9d4eefbaf72ca113002216f95c61f34fe6e1bf (patch) | |
| tree | cdfd153eba8ff472dd5ff8712835fdee65b710b1 /src | |
| parent | c7017b3b3ef687e59c619c9b39cb73f0b93c0dff (diff) | |
| parent | f78ee1aff1184c08b8d82f96fb9077586d1a4ed0 (diff) | |
| download | rust-ee9d4eefbaf72ca113002216f95c61f34fe6e1bf.tar.gz rust-ee9d4eefbaf72ca113002216f95c61f34fe6e1bf.zip | |
rollup merge of #24663: steveklabnik/gh24639
Fixes #24639
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/trpl/structs.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/doc/trpl/structs.md b/src/doc/trpl/structs.md index ff249d6043c..fcf928e427c 100644 --- a/src/doc/trpl/structs.md +++ b/src/doc/trpl/structs.md @@ -87,3 +87,33 @@ fn main() { point.y = 6; // this causes an error } ``` + +# Update syntax + +A `struct` can include `..` to indicate that you want to use a copy of some +other struct for some of the values. For example: + +```rust +struct Point3d { + x: i32, + y: i32, + z: i32, +} + +let mut point = Point3d { x: 0, y: 0, z: 0 }; +point = Point3d { y: 1, .. point }; +``` + +This gives `point` a new `y`, but keeps the old `x` and `z` values. It doesn’t +have to be the same `struct` either, you can use this syntax when making new +ones, and it will copy the values you don’t specify: + +```rust +# struct Point3d { +# x: i32, +# y: i32, +# z: i32, +# } +let origin = Point3d { x: 0, y: 0, z: 0 }; +let point = Point3d { z: 1, x: 2, .. origin }; +``` |
