about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-18 05:26:38 +0000
committerbors <bors@rust-lang.org>2014-06-18 05:26:38 +0000
commit410d70b5af30a4e5d566b981c9bf1b10b12b796b (patch)
treef2871e5e255ad92b9a19ea68efbc51e92fbb0ba8
parentd6736a1440d42f6af967a8a20ab8d73522112b72 (diff)
parentfeceb1276e3f7848fb6bee0a130065f6b1c56daf (diff)
downloadrust-410d70b5af30a4e5d566b981c9bf1b10b12b796b.tar.gz
rust-410d70b5af30a4e5d566b981c9bf1b10b12b796b.zip
auto merge of #14992 : nathantypanski/rust/collect-docs, r=huonw
This updates the documentation for result::collect() and
option::collect() to use the new-style syntax for owned pointers and
vectors.

closes #14991
-rw-r--r--src/libcore/option.rs18
-rw-r--r--src/libcore/result.rs18
2 files changed, 22 insertions, 14 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index a71727c3f8e..a4d33ae8028 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -574,13 +574,17 @@ impl<A> ExactSize<A> for Item<A> {}
 /// Here is an example which increments every integer in a vector,
 /// checking for overflow:
 ///
-///     fn inc_conditionally(x: uint) -> Option<uint> {
-///         if x == uint::MAX { return None; }
-///         else { return Some(x+1u); }
-///     }
-///     let v = [1u, 2, 3];
-///     let res = collect(v.iter().map(|&x| inc_conditionally(x)));
-///     assert!(res == Some(~[2u, 3, 4]));
+/// ```rust
+/// use std::option;
+/// use std::uint;
+///
+/// let v = vec!(1u, 2u);
+/// let res: Option<Vec<uint>> = option::collect(v.iter().map(|x: &uint|
+///     if *x == uint::MAX { None }
+///     else { Some(x + 1) }
+/// ));
+/// assert!(res == Some(vec!(2u, 3u)));
+/// ```
 #[inline]
 pub fn collect<T, Iter: Iterator<Option<T>>, V: FromIterator<T>>(iter: Iter) -> Option<V> {
     // FIXME(#11084): This should be twice as fast once this bug is closed.
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 180addfebcf..3f82190e6b7 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -572,13 +572,17 @@ impl<T: Show, E> Result<T, E> {
 /// Here is an example which increments every integer in a vector,
 /// checking for overflow:
 ///
-///     fn inc_conditionally(x: uint) -> Result<uint, &'static str> {
-///         if x == uint::MAX { return Err("overflow"); }
-///         else { return Ok(x+1u); }
-///     }
-///     let v = [1u, 2, 3];
-///     let res = collect(v.iter().map(|&x| inc_conditionally(x)));
-///     assert!(res == Ok(~[2u, 3, 4]));
+/// ```rust
+/// use std::result;
+/// use std::uint;
+///
+/// let v = vec!(1u, 2u);
+/// let res: Result<Vec<uint>, &'static str> = result::collect(v.iter().map(|x: &uint|
+///     if *x == uint::MAX { Err("Overflow!") }
+///     else { Ok(x + 1) }
+/// ));
+/// assert!(res == Ok(vec!(2u, 3u)));
+/// ```
 #[inline]
 pub fn collect<T, E, Iter: Iterator<Result<T, E>>, V: FromIterator<T>>(iter: Iter) -> Result<V, E> {
     // FIXME(#11084): This should be twice as fast once this bug is closed.