From cf4864a7a580fcb957c44c8cc64ac410dee6a694 Mon Sep 17 00:00:00 2001 From: Utkarsh Kukreti Date: Sun, 1 Jun 2014 01:20:52 +0530 Subject: [PATCH] Fix docs for `core::result::Result::map`. `reader.read_line()` includes trailing newline char, which makes `from_str` always return `None`. --- src/libcore/result.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index f3ec95d958247..7c178d295dd96 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -432,11 +432,13 @@ impl Result { /// let line: IoResult = reader.read_line(); /// // Convert the string line to a number using `map` and `from_str` /// let val: IoResult = line.map(|line| { - /// from_str::(line.as_slice()).unwrap_or(0) + /// from_str::(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(self, op: |T| -> U) -> Result {