Skip to content

Commit 07a2dd4

Browse files
committed
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.
2 parents 4bf5c99 + 496bd63 commit 07a2dd4

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/libcore/result.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1060,12 +1060,9 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> {
10601060
/// checking for overflow:
10611061
///
10621062
/// ```
1063-
/// use std::u32;
1064-
///
10651063
/// let v = vec![1, 2];
1066-
/// let res: Result<Vec<u32>, &'static str> = v.iter().map(|&x: &u32|
1067-
/// if x == u32::MAX { Err("Overflow!") }
1068-
/// else { Ok(x + 1) }
1064+
/// let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
1065+
/// x.checked_add(1).ok_or("Overflow!")
10691066
/// ).collect();
10701067
/// assert!(res == Ok(vec![2, 3]));
10711068
/// ```
@@ -1126,4 +1123,4 @@ impl<T,E> ops::Try for Result<T, E> {
11261123
fn from_error(v: E) -> Self {
11271124
Err(v)
11281125
}
1129-
}
1126+
}

0 commit comments

Comments
 (0)