about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-07-06 18:25:39 -0700
committerBrian Anderson <banderson@mozilla.com>2012-07-06 18:25:39 -0700
commit28fec95c5963bbd524f4271cb7cac63dcd2ec0cf (patch)
tree86cc1cfbdb9a04669dd8644beb1aa8ac5e8c3bf1
parentaf199f2edb0e5a85af7fdd2b8b85173f0928b512 (diff)
downloadrust-28fec95c5963bbd524f4271cb7cac63dcd2ec0cf.tar.gz
rust-28fec95c5963bbd524f4271cb7cac63dcd2ec0cf.zip
tutorial: Add some work on borrowed pointers
-rw-r--r--doc/tutorial.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/doc/tutorial.md b/doc/tutorial.md
index 301ca6cf5cc..f72557216ad 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -1557,6 +1557,33 @@ to other tasks. The sending task will give up ownership of the box,
 and won't be able to access it afterwards. The receiving task will
 become the sole owner of the box.
 
+### Borrowed Pointers
+
+Rust borrowed pointers are a general purpose reference/pointer type,
+similar to the C++ reference type, but guaranteed to point to valid
+memory. In contrast to unique pointers, where the holder of a unique
+pointer is the owner of the pointed-to memory, borrowed pointers never
+imply ownership. Pointers may be borrowed from any type, in which case
+the pointer is guaranteed not to outlive the value it points to.
+
+~~~~
+# fn work_with_foo_by_pointer(f: &str) { }
+let foo = "foo";
+work_with_foo_by_pointer(&foo);
+~~~~
+
+The following shows an example of what is _not_ possible with borrowed
+pointers. If you were able to write this then the pointer to `foo`
+would outlive `foo` itself.
+
+~~~~ {.ignore}
+let foo_ptr;
+{
+    let foo = "foo";
+    foo_ptr = &foo;
+}
+~~~~
+
 ### Mutability
 
 All pointer types have a mutable variant, written `@mut T` or `~mut