Skip to content

Commit

Permalink
Fix docs for core::result::Result::map.
Browse files Browse the repository at this point in the history
`reader.read_line()` includes trailing newline char, which makes
`from_str` always return `None`.
  • Loading branch information
utkarshkukreti committed Jun 1, 2014
1 parent 5527c5d commit cf4864a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libcore/result.rs
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

5 comments on commit cf4864a

@bors
Copy link
Contributor

@bors bors commented on cf4864a Jun 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at utkarshkukreti@cf4864a

@bors
Copy link
Contributor

@bors bors commented on cf4864a Jun 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging utkarshkukreti/rust/fix-docs-for-result-map = cf4864a into auto

@bors
Copy link
Contributor

@bors bors commented on cf4864a Jun 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utkarshkukreti/rust/fix-docs-for-result-map = cf4864a merged ok, testing candidate = c605c2b

@bors
Copy link
Contributor

@bors bors commented on cf4864a Jun 1, 2014

@bors
Copy link
Contributor

@bors bors commented on cf4864a Jun 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c605c2b

Please sign in to comment.