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.
This commit is contained in:
commit
07a2dd41c5
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user