Skip to content

Commit c605c2b

Browse files
committed
auto merge of #14580 : utkarshkukreti/rust/fix-docs-for-result-map, r=alexcrichton
`reader.read_line()` includes trailing newline char, which makes `from_str` always return `None`.
2 parents dfaea70 + cf4864a commit c605c2b

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)