Skip to content

Commit

Permalink
auto merge of #14580 : utkarshkukreti/rust/fix-docs-for-result-map, r…
Browse files Browse the repository at this point in the history
…=alexcrichton

`reader.read_line()` includes trailing newline char, which makes
`from_str` always return `None`.
  • Loading branch information
bors committed Jun 1, 2014
2 parents dfaea70 + cf4864a commit c605c2b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,13 @@ impl<T, E> Result<T, E> {
/// let line: IoResult<String> = reader.read_line();
/// // Convert the string line to a number using `map` and `from_str`
/// let val: IoResult<int> = line.map(|line| {
/// from_str::<int>(line.as_slice()).unwrap_or(0)
/// from_str::<int>(line.as_slice().trim_right()).unwrap_or(0)
/// });
/// // Add the value if there were no errors, otherwise add 0
/// sum += val.ok().unwrap_or(0);
/// }
///
/// assert!(sum == 10);
/// ~~~
#[inline]
pub fn map<U>(self, op: |T| -> U) -> Result<U,E> {
Expand Down

0 comments on commit c605c2b

Please sign in to comment.