about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-06-11 14:29:56 +0000
committerbors <bors@rust-lang.org>2017-06-11 14:29:56 +0000
commit07a2dd41c5fed11f649079e34c4444f5e18a75cd (patch)
tree58c5744098264c1d1c34f5e97630da3baac5bbc1
parent4bf5c99afc75f411a4e064150781eefc749c10df (diff)
parent496bd63f33ac649a637259ed359da7b9f1a65f80 (diff)
downloadrust-07a2dd41c5fed11f649079e34c4444f5e18a75cd.tar.gz
rust-07a2dd41c5fed11f649079e34c4444f5e18a75cd.zip
Auto merge of #42569 - birkenfeld:patch-2, r=frewsxcv
Simplify FromIterator example of Result

The previous version may be clearer for newcomers, but this is how you'd write it idiomaticly.
-rw-r--r--src/libcore/result.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index df7fff0df92..88a93492de9 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -1060,12 +1060,9 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
     /// checking for overflow:
     ///
     /// ```
-    /// use std::u32;
-    ///
     /// let v = vec![1, 2];
-    /// let res: Result<Vec<u32>, &'static str> = v.iter().map(|&x: &u32|
-    ///     if x == u32::MAX { Err("Overflow!") }
-    ///     else { Ok(x + 1) }
+    /// let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
+    ///     x.checked_add(1).ok_or("Overflow!")
     /// ).collect();
     /// assert!(res == Ok(vec![2, 3]));
     /// ```
@@ -1126,4 +1123,4 @@ impl<T,E> ops::Try for Result<T, E> {
     fn from_error(v: E) -> Self {
         Err(v)
     }
-}
\ No newline at end of file
+}