Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8a26266f
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,发现更多精彩内容 >>
提交
8a26266f
编写于
11月 16, 2013
作者:
S
Steven Fackler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change Mut::map to Mut::with
上级
bb39cc3a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
19 deletion
+19
-19
src/libstd/mutable.rs
src/libstd/mutable.rs
+12
-12
src/libstd/rc.rs
src/libstd/rc.rs
+4
-4
src/libstd/rt/comm.rs
src/libstd/rt/comm.rs
+3
-3
未找到文件。
src/libstd/mutable.rs
浏览文件 @
8a26266f
...
...
@@ -118,7 +118,7 @@ pub fn borrow_mut<'a>(&'a self) -> RefMut<'a, T> {
///
/// Fails if the value is currently mutably borrowed.
#[inline]
pub
fn
map
<
U
>
(
&
self
,
blk
:
|
&
T
|
->
U
)
->
U
{
pub
fn
with
<
U
>
(
&
self
,
blk
:
|
&
T
|
->
U
)
->
U
{
let
ptr
=
self
.borrow
();
blk
(
ptr
.get
())
}
...
...
@@ -129,7 +129,7 @@ pub fn map<U>(&self, blk: |&T| -> U) -> U {
///
/// Fails if the value is currently borrowed.
#[inline]
pub
fn
map
_mut
<
U
>
(
&
self
,
blk
:
|
&
mut
T
|
->
U
)
->
U
{
pub
fn
with
_mut
<
U
>
(
&
self
,
blk
:
|
&
mut
T
|
->
U
)
->
U
{
let
mut
ptr
=
self
.borrow_mut
();
blk
(
ptr
.get
())
}
...
...
@@ -260,39 +260,39 @@ fn double_borrow_single_release_no_borrow_mut() {
}
#[test]
fn
map
_ok
()
{
fn
with
_ok
()
{
let
x
=
Mut
::
new
(
0
);
assert_eq!
(
1
,
x
.
map
(|
x
|
*
x
+
1
));
assert_eq!
(
1
,
x
.
with
(|
x
|
*
x
+
1
));
}
#[test]
#[should_fail]
fn
mut_borrow_
map
()
{
fn
mut_borrow_
with
()
{
let
x
=
Mut
::
new
(
0
);
let
_
b1
=
x
.borrow_mut
();
x
.
map
(|
x
|
*
x
+
1
);
x
.
with
(|
x
|
*
x
+
1
);
}
#[test]
fn
borrow_
map
()
{
fn
borrow_
with
()
{
let
x
=
Mut
::
new
(
0
);
let
_
b1
=
x
.borrow
();
assert_eq!
(
1
,
x
.
map
(|
x
|
*
x
+
1
));
assert_eq!
(
1
,
x
.
with
(|
x
|
*
x
+
1
));
}
#[test]
fn
map
_mut_ok
()
{
fn
with
_mut_ok
()
{
let
x
=
Mut
::
new
(
0
);
x
.
map
_mut
(|
x
|
*
x
+=
1
);
x
.
with
_mut
(|
x
|
*
x
+=
1
);
let
b
=
x
.borrow
();
assert_eq!
(
1
,
*
b
.get
());
}
#[test]
#[should_fail]
fn
borrow_
map
_mut
()
{
fn
borrow_
with
_mut
()
{
let
x
=
Mut
::
new
(
0
);
let
_
b
=
x
.borrow
();
x
.
map
_mut
(|
x
|
*
x
+=
1
);
x
.
with
_mut
(|
x
|
*
x
+=
1
);
}
}
src/libstd/rc.rs
浏览文件 @
8a26266f
...
...
@@ -111,20 +111,20 @@ mod test_rc {
fn
test_clone
()
{
let
x
=
Rc
::
from_send
(
Mut
::
new
(
5
));
let
y
=
x
.clone
();
do
x
.borrow
()
.
map
_mut
|
inner
|
{
do
x
.borrow
()
.
with
_mut
|
inner
|
{
*
inner
=
20
;
}
assert_eq!
(
y
.borrow
()
.
map
(|
v
|
*
v
),
20
);
assert_eq!
(
y
.borrow
()
.
with
(|
v
|
*
v
),
20
);
}
#[test]
fn
test_deep_clone
()
{
let
x
=
Rc
::
from_send
(
Mut
::
new
(
5
));
let
y
=
x
.deep_clone
();
do
x
.borrow
()
.
map
_mut
|
inner
|
{
do
x
.borrow
()
.
with
_mut
|
inner
|
{
*
inner
=
20
;
}
assert_eq!
(
y
.borrow
()
.
map
(|
v
|
*
v
),
5
);
assert_eq!
(
y
.borrow
()
.
with
(|
v
|
*
v
),
5
);
}
#[test]
...
...
src/libstd/rt/comm.rs
浏览文件 @
8a26266f
...
...
@@ -506,7 +506,7 @@ fn try_recv(&self) -> Option<T> {
impl
<
T
:
Send
>
Peekable
<
T
>
for
Port
<
T
>
{
fn
peek
(
&
self
)
->
bool
{
self
.next
.
map
_mut
(|
p
|
p
.get_mut_ref
()
.peek
())
self
.next
.
with
_mut
(|
p
|
p
.get_mut_ref
()
.peek
())
}
}
...
...
@@ -517,7 +517,7 @@ fn peek(&self) -> bool {
impl
<
'self
,
T
:
Send
>
SelectInner
for
&
'self
Port
<
T
>
{
#[inline]
fn
optimistic_check
(
&
mut
self
)
->
bool
{
do
self
.next.
map
_mut
|
pone
|
{
pone
.get_mut_ref
()
.optimistic_check
()
}
do
self
.next.
with
_mut
|
pone
|
{
pone
.get_mut_ref
()
.optimistic_check
()
}
}
#[inline]
...
...
@@ -528,7 +528,7 @@ fn block_on(&mut self, sched: &mut Scheduler, task: BlockedTask) -> bool {
#[inline]
fn
unblock_from
(
&
mut
self
)
->
bool
{
do
self
.next.
map
_mut
|
pone
|
{
pone
.get_mut_ref
()
.unblock_from
()
}
do
self
.next.
with
_mut
|
pone
|
{
pone
.get_mut_ref
()
.unblock_from
()
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录