]> git.lizzy.rs Git - rust.git/commitdiff
tutorial: add an example of freezing a managed box
authorDaniel Micay <danielmicay@gmail.com>
Fri, 29 Mar 2013 19:34:14 +0000 (15:34 -0400)
committerDaniel Micay <danielmicay@gmail.com>
Fri, 29 Mar 2013 19:45:10 +0000 (15:45 -0400)
doc/tutorial.md

index fbeda4257f52384c1c44ca74114657d052ba38c0..7518e3ef6761453aa4ef01e2214a387d374d7346 100644 (file)
@@ -1173,10 +1173,7 @@ For a more in-depth explanation of borrowed pointers, read the
 ## Freezing
 
 Borrowing an immutable pointer to an object freezes it and prevents mutation.
-`Owned` objects have freezing enforced statically at compile-time. Mutable
-managed boxes handle freezing dynamically when any of their contents are
-borrowed, and the task will fail if an attempt to modify them is made while
-they are frozen.
+`Owned` objects have freezing enforced statically at compile-time.
 
 ~~~~
 let mut x = 5;
@@ -1186,6 +1183,20 @@ let mut x = 5;
 // x is now unfrozen again
 ~~~~
 
+Mutable managed boxes handle freezing dynamically when any of their contents
+are borrowed, and the task will fail if an attempt to modify them is made while
+they are frozen:
+
+~~~~
+let x = @mut 5;
+let y = x;
+{
+    let y = &*y; // the managed box is now frozen
+    // modifying it through x or y will cause a task failure
+}
+// the box is now unfrozen again
+~~~~
+
 # Dereferencing pointers
 
 Rust uses the unary star operator (`*`) to access the contents of a