Skip to content

Mention that structs can contain &mut Ts #30699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/doc/book/structs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down