Simplify FromIterator example of Result

This commit is contained in:
Georg Brandl 2017-06-09 22:20:32 +02:00 committed by GitHub
parent 5fe923d434
commit 496bd63f33

View file

@ -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)
}
}
}