about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2016-01-06 18:31:57 -0500
committerSteve Klabnik <steve@steveklabnik.com>2016-01-06 18:31:57 -0500
commitba41e3c29276720972cd0611d4b95db7233db610 (patch)
treee1d5f8c8073396f1f00d14fb985ba77db302e942
parent9239b64cd6b2bf6aaf7f121cf5c0fe69faa3e912 (diff)
parent723ead6c9cbe28806f97f43ebfc6df95e758734a (diff)
Rollup merge of #30699 - steveklabnik:gh30254, r=apasel422
Fixes #30254
-rw-r--r--src/doc/book/structs.md29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/doc/book/structs.md b/src/doc/book/structs.md
index 1d70ee27869..75d0093b147 100644
--- a/src/doc/book/structs.md
+++ b/src/doc/book/structs.md
@@ -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