Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a5a17399
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5a17399
编写于
8月 18, 2017
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add missing urls for Result struct
上级
86fd9a55
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
27 deletion
+73
-27
src/libcore/result.rs
src/libcore/result.rs
+73
-27
未找到文件。
src/libcore/result.rs
浏览文件 @
a5a17399
...
...
@@ -244,9 +244,12 @@
use
iter
::{
FromIterator
,
FusedIterator
,
TrustedLen
};
use
ops
;
/// `Result` is a type that represents either success (
`Ok`) or failure (`Err`
).
/// `Result` is a type that represents either success (
[`Ok`]) or failure ([`Err`]
).
///
/// See the [`std::result`](index.html) module documentation for details.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
#[derive(Clone,
Copy,
PartialEq,
PartialOrd,
Eq,
Ord,
Debug,
Hash)]
#[must_use]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
...
...
@@ -269,7 +272,9 @@ impl<T, E> Result<T, E> {
// Querying the contained values
/////////////////////////////////////////////////////////////////////////
/// Returns `true` if the result is `Ok`.
/// Returns `true` if the result is [`Ok`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
///
/// # Examples
///
...
...
@@ -291,7 +296,9 @@ pub fn is_ok(&self) -> bool {
}
}
/// Returns `true` if the result is `Err`.
/// Returns `true` if the result is [`Err`].
///
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -433,10 +440,13 @@ pub fn as_mut(&mut self) -> Result<&mut T, &mut E> {
/////////////////////////////////////////////////////////////////////////
/// Maps a `Result<T, E>` to `Result<U, E>` by applying a function to a
/// contained
`Ok` value, leaving an `Err`
value untouched.
/// contained
[`Ok`] value, leaving an [`Err`]
value untouched.
///
/// This function can be used to compose the results of two functions.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Print the numbers on each line of a string multiplied by two.
...
...
@@ -461,11 +471,14 @@ pub fn map<U, F: FnOnce(T) -> U>(self, op: F) -> Result<U,E> {
}
/// Maps a `Result<T, E>` to `Result<T, F>` by applying a function to a
/// contained
`Err` value, leaving an `Ok`
value untouched.
/// contained
[`Err`] value, leaving an [`Ok`]
value untouched.
///
/// This function can be used to pass through a successful result while handling
/// an error.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
...
...
@@ -546,7 +559,10 @@ pub fn iter_mut(&mut self) -> IterMut<T> {
// Boolean operations on the values, eager and lazy
/////////////////////////////////////////////////////////////////////////
/// Returns `res` if the result is `Ok`, otherwise returns the `Err` value of `self`.
/// Returns `res` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -578,7 +594,10 @@ pub fn and<U>(self, res: Result<U, E>) -> Result<U, E> {
}
}
/// Calls `op` if the result is `Ok`, otherwise returns the `Err` value of `self`.
/// Calls `op` if the result is [`Ok`], otherwise returns the [`Err`] value of `self`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// This function can be used for control flow based on `Result` values.
///
...
...
@@ -604,7 +623,10 @@ pub fn and_then<U, F: FnOnce(T) -> Result<U, E>>(self, op: F) -> Result<U, E> {
}
}
/// Returns `res` if the result is `Err`, otherwise returns the `Ok` value of `self`.
/// Returns `res` if the result is [`Err`], otherwise returns the [`Ok`] value of `self`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -636,10 +658,13 @@ pub fn or<F>(self, res: Result<T, F>) -> Result<T, F> {
}
}
/// Calls `op` if the result is
`Err`, otherwise returns the `Ok`
value of `self`.
/// Calls `op` if the result is
[`Err`], otherwise returns the [`Ok`]
value of `self`.
///
/// This function can be used for control flow based on result values.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
...
...
@@ -662,9 +687,12 @@ pub fn or_else<F, O: FnOnce(E) -> Result<T, F>>(self, op: O) -> Result<T, F> {
}
}
/// Unwraps a result, yielding the content of an
`Ok`
.
/// Unwraps a result, yielding the content of an
[`Ok`]
.
/// Else, it returns `optb`.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
/// Basic usage:
...
...
@@ -686,8 +714,11 @@ pub fn unwrap_or(self, optb: T) -> T {
}
}
/// Unwraps a result, yielding the content of an `Ok`.
/// If the value is an `Err` then it calls `op` with its value.
/// Unwraps a result, yielding the content of an [`Ok`].
/// If the value is an [`Err`] then it calls `op` with its value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -710,12 +741,15 @@ pub fn unwrap_or_else<F: FnOnce(E) -> T>(self, op: F) -> T {
}
impl
<
T
,
E
:
fmt
::
Debug
>
Result
<
T
,
E
>
{
/// Unwraps a result, yielding the content of an
`Ok`
.
/// Unwraps a result, yielding the content of an
[`Ok`]
.
///
/// # Panics
///
/// Panics if the value is an `Err`, with a panic message provided by the
/// `Err`'s value.
/// Panics if the value is an [`Err`], with a panic message provided by the
/// [`Err`]'s value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -739,12 +773,15 @@ pub fn unwrap(self) -> T {
}
}
/// Unwraps a result, yielding the content of an
`Ok`
.
/// Unwraps a result, yielding the content of an
[`Ok`]
.
///
/// # Panics
///
/// Panics if the value is an `Err`, with a panic message including the
/// passed message, and the content of the `Err`.
/// Panics if the value is an [`Err`], with a panic message including the
/// passed message, and the content of the [`Err`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -765,12 +802,16 @@ pub fn expect(self, msg: &str) -> T {
}
impl
<
T
:
fmt
::
Debug
,
E
>
Result
<
T
,
E
>
{
/// Unwraps a result, yielding the content of an
`Err`
.
/// Unwraps a result, yielding the content of an
[`Err`]
.
///
/// # Panics
///
/// Panics if the value is an `Ok`, with a custom panic message provided
/// by the `Ok`'s value.
/// Panics if the value is an [`Ok`], with a custom panic message provided
/// by the [`Ok`]'s value.
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
///
/// # Examples
///
...
...
@@ -792,12 +833,15 @@ pub fn unwrap_err(self) -> E {
}
}
/// Unwraps a result, yielding the content of an
`Err`
.
/// Unwraps a result, yielding the content of an
[`Err`]
.
///
/// # Panics
///
/// Panics if the value is an `Ok`, with a panic message including the
/// passed message, and the content of the `Ok`.
/// Panics if the value is an [`Ok`], with a panic message including the
/// passed message, and the content of the [`Ok`].
///
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
///
/// # Examples
///
...
...
@@ -820,8 +864,8 @@ pub fn expect_err(self, msg: &str) -> E {
impl
<
T
:
Default
,
E
>
Result
<
T
,
E
>
{
/// Returns the contained value or a default
///
/// Consumes the `self` argument then, if
`Ok`
, returns the contained
/// value, otherwise if
`Err`
, returns the default value for that
/// Consumes the `self` argument then, if
[`Ok`]
, returns the contained
/// value, otherwise if
[`Err`]
, returns the default value for that
/// type.
///
/// # Examples
...
...
@@ -829,7 +873,7 @@ impl<T: Default, E> Result<T, E> {
/// Convert a string to an integer, turning poorly-formed strings
/// into 0 (the default value for integers). [`parse`] converts
/// a string to any other type that implements [`FromStr`], returning an
///
`Err`
on error.
///
[`Err`]
on error.
///
/// ```
/// let good_year_from_input = "1909";
...
...
@@ -843,6 +887,8 @@ impl<T: Default, E> Result<T, E> {
///
/// [`parse`]: ../../std/primitive.str.html#method.parse
/// [`FromStr`]: ../../std/str/trait.FromStr.html
/// [`Ok`]: enum.Result.html#variant.Ok
/// [`Err`]: enum.Result.html#variant.Err
#[inline]
#[stable(feature
=
"result_unwrap_or_default"
,
since
=
"1.16.0"
)]
pub
fn
unwrap_or_default
(
self
)
->
T
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录