Skip to content

Commit

Permalink
Auto merge of #42569 - birkenfeld:patch-2, r=frewsxcv
Browse files Browse the repository at this point in the history
Simplify FromIterator example of Result

The previous version may be clearer for newcomers, but this is how you'd write it idiomaticly.
  • Loading branch information
bors committed Jun 11, 2017
2 parents 4bf5c99 + 496bd63 commit 07a2dd4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
/// ```
Expand Down Expand Up @@ -1126,4 +1123,4 @@ impl<T,E> ops::Try for Result<T, E> {
fn from_error(v: E) -> Self {
Err(v)
}
}
}

0 comments on commit 07a2dd4

Please sign in to comment.