Mention that structs can contain &mut Ts

Fixes #30254
This commit is contained in:
Steve Klabnik 2016-01-04 12:44:54 -05:00
parent 191ff2d8fd
commit 723ead6c9c

View File

@ -88,6 +88,35 @@ fn main() {
}
```
Your structure can still contain `&mut` pointers, which will let
you do some kinds of mutation:
```rust
struct Point {
x: i32,
y: i32,
}
struct PointRef<'a> {
x: &'a mut i32,
y: &'a mut i32,
}
fn main() {
let mut point = Point { x: 0, y: 0 };
{
let r = PointRef { x: &mut point.x, y: &mut point.y };
*r.x = 5;
*r.y = 6;
}
assert_eq!(5, point.x);
assert_eq!(6, point.y);
}
```
# Update syntax
A `struct` can include `..` to indicate that you want to use a copy of some