Skip to content

Commit ee9d4ee

Browse files
committed
rollup merge of #24663: steveklabnik/gh24639
Fixes #24639
2 parents c7017b3 + f78ee1a commit ee9d4ee

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/doc/trpl/structs.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,33 @@ fn main() {
8787
point.y = 6; // this causes an error
8888
}
8989
```
90+
91+
# Update syntax
92+
93+
A `struct` can include `..` to indicate that you want to use a copy of some
94+
other struct for some of the values. For example:
95+
96+
```rust
97+
struct Point3d {
98+
x: i32,
99+
y: i32,
100+
z: i32,
101+
}
102+
103+
let mut point = Point3d { x: 0, y: 0, z: 0 };
104+
point = Point3d { y: 1, .. point };
105+
```
106+
107+
This gives `point` a new `y`, but keeps the old `x` and `z` values. It doesn’t
108+
have to be the same `struct` either, you can use this syntax when making new
109+
ones, and it will copy the values you don’t specify:
110+
111+
```rust
112+
# struct Point3d {
113+
# x: i32,
114+
# y: i32,
115+
# z: i32,
116+
# }
117+
let origin = Point3d { x: 0, y: 0, z: 0 };
118+
let point = Point3d { z: 1, x: 2, .. origin };
119+
```

0 commit comments

Comments
 (0)