Skip to content

Commit cf4864a

Browse files
Fix docs for core::result::Result::map.
`reader.read_line()` includes trailing newline char, which makes `from_str` always return `None`.
1 parent 5527c5d commit cf4864a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/libcore/result.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,13 @@ impl<T, E> Result<T, E> {
432432
/// let line: IoResult<String> = reader.read_line();
433433
/// // Convert the string line to a number using `map` and `from_str`
434434
/// let val: IoResult<int> = line.map(|line| {
435-
/// from_str::<int>(line.as_slice()).unwrap_or(0)
435+
/// from_str::<int>(line.as_slice().trim_right()).unwrap_or(0)
436436
/// });
437437
/// // Add the value if there were no errors, otherwise add 0
438438
/// sum += val.ok().unwrap_or(0);
439439
/// }
440+
///
441+
/// assert!(sum == 10);
440442
/// ~~~
441443
#[inline]
442444
pub fn map<U>(self, op: |T| -> U) -> Result<U,E> {

0 commit comments

Comments
 (0)