Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7f9c5aae
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
7f9c5aae
编写于
9月 12, 2013
作者:
E
Erick Tryzelaar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
std: Restore Option::chain{,_mut}_ref as and_then{,_mut}_ref
上级
7c08abb0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
31 deletion
+31
-31
src/librustc/middle/trans/common.rs
src/librustc/middle/trans/common.rs
+1
-4
src/librustc/middle/typeck/astconv.rs
src/librustc/middle/typeck/astconv.rs
+4
-11
src/libstd/iter.rs
src/libstd/iter.rs
+2
-12
src/libstd/option.rs
src/libstd/option.rs
+24
-4
未找到文件。
src/librustc/middle/trans/common.rs
浏览文件 @
7f9c5aae
...
...
@@ -505,10 +505,7 @@ fn info(&self) -> Option<NodeInfo> {
impl
get_node_info
for
Option
<@
ast
::
Expr
>
{
fn
info
(
&
self
)
->
Option
<
NodeInfo
>
{
match
*
self
{
Some
(
ref
s
)
=>
s
.info
(),
None
=>
None
,
}
self
.and_then_ref
(|
s
|
s
.info
())
}
}
...
...
src/librustc/middle/typeck/astconv.rs
浏览文件 @
7f9c5aae
...
...
@@ -745,17 +745,10 @@ pub fn ty_of_closure<AC:AstConv,RS:RegionScope + Clone + 'static>(
RegionParamNames
(
bound_lifetime_names
.clone
()));
let
input_tys
=
do
decl
.inputs
.iter
()
.enumerate
()
.map
|(
i
,
a
)|
{
let
expected_arg_ty
=
match
expected_sig
{
Some
(
ref
e
)
=>
{
// no guarantee that the correct number of expected args
// were supplied
if
i
<
e
.inputs
.len
()
{
Some
(
e
.inputs
[
i
])
}
else
{
None
}
}
None
=>
None
,
let
expected_arg_ty
=
do
expected_sig
.and_then_ref
|
e
|
{
// no guarantee that the correct number of expected args
// were supplied
if
i
<
e
.inputs
.len
()
{
Some
(
e
.inputs
[
i
])}
else
{
None
}
};
ty_of_arg
(
this
,
&
rb
,
a
,
expected_arg_ty
)
}
.collect
();
...
...
src/libstd/iter.rs
浏览文件 @
7f9c5aae
...
...
@@ -1504,12 +1504,7 @@ fn next(&mut self) -> Option<B> {
}
}
match
self
.iter
.next
()
.map_move
(|
x
|
(
self
.f
)(
x
))
{
None
=>
{
return
match
self
.backiter
{
Some
(
ref
mut
it
)
=>
it
.next
(),
None
=>
None
,
};
}
None
=>
return
self
.backiter
.and_then_mut_ref
(|
it
|
it
.next
()),
next
=>
self
.frontiter
=
next
,
}
}
...
...
@@ -1541,12 +1536,7 @@ fn next_back(&mut self) -> Option<B> {
}
}
match
self
.iter
.next_back
()
.map_move
(|
x
|
(
self
.f
)(
x
))
{
None
=>
{
return
match
self
.frontiter
{
Some
(
ref
mut
it
)
=>
it
.next_back
(),
None
=>
None
,
};
}
None
=>
return
self
.frontiter
.and_then_mut_ref
(|
it
|
it
.next_back
()),
next
=>
self
.backiter
=
next
,
}
}
...
...
src/libstd/option.rs
浏览文件 @
7f9c5aae
...
...
@@ -138,8 +138,8 @@ pub fn and(self, optb: Option<T>) -> Option<T> {
}
}
/// Returns `None` if the option is `None`, otherwise calls
and returns
the
///
value of `f`
.
/// Returns `None` if the option is `None`, otherwise calls
`f` with
the
///
wrapped value and returns the result
.
#[inline]
pub
fn
and_then
<
U
>
(
self
,
f
:
&
fn
(
T
)
->
Option
<
U
>
)
->
Option
<
U
>
{
match
self
{
...
...
@@ -148,6 +148,26 @@ pub fn and_then<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
}
}
/// Returns `None` if the option is `None`, otherwise calls `f` with a
/// reference to the wrapped value and returns the result.
#[inline]
pub
fn
and_then_ref
<
'a
,
U
>
(
&
'a
self
,
f
:
&
fn
(
&
'a
T
)
->
Option
<
U
>
)
->
Option
<
U
>
{
match
*
self
{
Some
(
ref
x
)
=>
f
(
x
),
None
=>
None
}
}
/// Returns `None` if the option is `None`, otherwise calls `f` with a
/// mutable reference to the wrapped value and returns the result.
#[inline]
pub
fn
and_then_mut_ref
<
'a
,
U
>
(
&
'a
mut
self
,
f
:
&
fn
(
&
'a
mut
T
)
->
Option
<
U
>
)
->
Option
<
U
>
{
match
*
self
{
Some
(
ref
mut
x
)
=>
f
(
x
),
None
=>
None
}
}
/// Returns the option if it contains a value, otherwise returns `optb`.
#[inline]
pub
fn
or
(
self
,
optb
:
Option
<
T
>
)
->
Option
<
T
>
{
...
...
@@ -157,8 +177,8 @@ pub fn or(self, optb: Option<T>) -> Option<T> {
}
}
/// Returns the option if it contains a value, otherwise calls
and returns the
///
value of `f`
.
/// Returns the option if it contains a value, otherwise calls
`f` and
///
returns the result
.
#[inline]
pub
fn
or_else
(
self
,
f
:
&
fn
()
->
Option
<
T
>
)
->
Option
<
T
>
{
match
self
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录