提交 cf4864a7 编写于 作者: U Utkarsh Kukreti

Fix docs for `core::result::Result::map`.

`reader.read_line()` includes trailing newline char, which makes
`from_str` always return `None`.
上级 5527c5dc
......@@ -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> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册