Skip to content

Commit c20e339

Browse files
committed
Rollup merge of rust-lang#30699 - steveklabnik:gh30254, r=apasel422
Fixes rust-lang#30254
2 parents 61ca87c + 723ead6 commit c20e339

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/doc/book/structs.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,35 @@ fn main() {
8888
}
8989
```
9090

91+
Your structure can still contain `&mut` pointers, which will let
92+
you do some kinds of mutation:
93+
94+
```rust
95+
struct Point {
96+
x: i32,
97+
y: i32,
98+
}
99+
100+
struct PointRef<'a> {
101+
x: &'a mut i32,
102+
y: &'a mut i32,
103+
}
104+
105+
fn main() {
106+
let mut point = Point { x: 0, y: 0 };
107+
108+
{
109+
let r = PointRef { x: &mut point.x, y: &mut point.y };
110+
111+
*r.x = 5;
112+
*r.y = 6;
113+
}
114+
115+
assert_eq!(5, point.x);
116+
assert_eq!(6, point.y);
117+
}
118+
```
119+
91120
# Update syntax
92121

93122
A `struct` can include `..` to indicate that you want to use a copy of some

0 commit comments

Comments
 (0)