about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authornoam <noam@clusterfoo.com>2014-03-23 16:05:01 -0400
committernoam <noam@clusterfoo.com>2014-03-23 18:29:58 -0400
commit7dfa4b298262fde037b5fbbb8fe20468d7306cbb (patch)
tree7455d80a42514452b803657198b719e6047b740c /src/doc
parent903e83889ade166bf62f1ee74df8bf8331ea17d1 (diff)
downloadrust-7dfa4b298262fde037b5fbbb8fe20468d7306cbb.tar.gz
rust-7dfa4b298262fde037b5fbbb8fe20468d7306cbb.zip
docs: named lifetimes
* Include tip given by Leo Testard in mailing list about labeled `break`
and `continue`:
https://mail.mozilla.org/pipermail/rust-dev/2014-March/009145.html
* cross-reference named lifetimes in tutorial -> lifetimes guide
* Broke named lifetimes section into two sub-sections.
* Added mention of `'static` lifetime.
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/guide-lifetimes.md25
-rw-r--r--src/doc/tutorial.md3
2 files changed, 24 insertions, 4 deletions
diff --git a/src/doc/guide-lifetimes.md b/src/doc/guide-lifetimes.md
index 69596b6e304..20268ce8bbe 100644
--- a/src/doc/guide-lifetimes.md
+++ b/src/doc/guide-lifetimes.md
@@ -559,9 +559,14 @@ points at a static constant).
 
 # Named lifetimes
 
-Let's look at named lifetimes in more detail. Named lifetimes allow
-for grouping of parameters by lifetime. For example, consider this
-function:
+Lifetimes can be named and referenced. For example, the special lifetime 
+`'static`, which does not go out of scope, can be used to create global
+variables and communicate between tasks (see the manual for usecases).
+
+## Parameter Lifetimes
+
+Named lifetimes allow for grouping of parameters by lifetime. 
+For example, consider this function:
 
 ~~~
 # struct Point {x: f64, y: f64}; // as before
@@ -655,6 +660,20 @@ fn select<'r, T>(shape: &Shape, threshold: f64,
 
 This is equivalent to the previous definition.
 
+## Labeled Control Structures
+
+Named lifetime notation can also be used to control the flow of execution:
+
+~~~
+'h: for i in range(0,10) {
+    'g: loop {
+        if i % 2 == 0 { continue 'h; }
+        if i == 9 { break 'h; }
+        break 'g;
+    }
+}
+~~~
+
 # Conclusion
 
 So there you have it: a (relatively) brief tour of the lifetime
diff --git a/src/doc/tutorial.md b/src/doc/tutorial.md
index bfa1a3a2a29..09539e6d59d 100644
--- a/src/doc/tutorial.md
+++ b/src/doc/tutorial.md
@@ -2103,7 +2103,8 @@ a `&T` pointer. `MutexArc` is an example of a *sharable* type with internal muta
 These are types that do not contain any data whose lifetime is bound to
 a particular stack frame. These are types that do not contain any
 references, or types where the only contained references
-have the `'static` lifetime.
+have the `'static` lifetime. (For more on named lifetimes and their uses, 
+see the [references and lifetimes guide][lifetimes].)
 
 > ***Note:*** These two traits were referred to as 'kinds' in earlier
 > iterations of the language, and often still are.