diff options
| author | bors <bors@rust-lang.org> | 2014-06-01 04:36:38 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-06-01 04:36:38 -0700 |
| commit | c605c2b57b412402e6b491e91852fd9dbadeb551 (patch) | |
| tree | d3b5753f369ff74b0d7ba0ce4c42ef64bcfcec7a /src/libcore | |
| parent | dfaea709631ab92625d2ab20eb0770707fe72770 (diff) | |
| parent | cf4864a7a580fcb957c44c8cc64ac410dee6a694 (diff) | |
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`.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/result.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 0762c7458d9..8928fa0ee04 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -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> { |
