]> git.lizzy.rs Git - rust.git/commitdiff
Fix docs for `core::result::Result::map`.
authorUtkarsh Kukreti <utkarshkukreti@gmail.com>
Sat, 31 May 2014 19:50:52 +0000 (01:20 +0530)
committerUtkarsh Kukreti <utkarshkukreti@gmail.com>
Sun, 1 Jun 2014 06:48:39 +0000 (12:18 +0530)
`reader.read_line()` includes trailing newline char, which makes
`from_str` always return `None`.

src/libcore/result.rs

index f3ec95d9582475643aba6e0d097c3d09fa790aee..7c178d295dd9640d373fe5bc02d954f2972ff70c 100644 (file)
@@ -432,11 +432,13 @@ pub fn as_mut<'r>(&'r mut self) -> Result<&'r mut T, &'r mut 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> {