about summary refs log tree commit diff
path: root/doc/tutorial.md
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-03-29 15:34:14 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-03-29 15:45:10 -0400
commit0189ef360092dbebfef5bdfd7a2ebe0c0ccc0f3c (patch)
tree431af679f2988aa9ee1c1f268e19c6b320690640 /doc/tutorial.md
parentf78af18127e2bc0075479e8495bfa63807e938fc (diff)
downloadrust-0189ef360092dbebfef5bdfd7a2ebe0c0ccc0f3c.tar.gz
rust-0189ef360092dbebfef5bdfd7a2ebe0c0ccc0f3c.zip
tutorial: add an example of freezing a managed box
Diffstat (limited to 'doc/tutorial.md')
-rw-r--r--doc/tutorial.md19
1 files changed, 15 insertions, 4 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md
index fbeda4257f5..7518e3ef676 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -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