Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bba0680c
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,发现更多精彩内容 >>
提交
bba0680c
编写于
5月 02, 2013
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libstd: Remove mutable fields from future and par
上级
92d2ec4d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
58 addition
and
23 deletion
+58
-23
src/libstd/future.rs
src/libstd/future.rs
+56
-21
src/libstd/par.rs
src/libstd/par.rs
+2
-2
未找到文件。
src/libstd/future.rs
浏览文件 @
bba0680c
...
...
@@ -29,7 +29,7 @@
#[doc
=
"The future type"
]
pub
struct
Future
<
A
>
{
priv
mut
state
:
FutureState
<
A
>
,
priv
state
:
FutureState
<
A
>
,
}
// FIXME(#2829) -- futures should not be copyable, because they close
...
...
@@ -47,13 +47,14 @@ fn finalize(&self) {}
/// Methods on the `future` type
pub
impl
<
A
:
Copy
>
Future
<
A
>
{
fn
get
(
&
self
)
->
A
{
fn
get
(
&
mut
self
)
->
A
{
//! Get the value of the future
*
(
self
.get_ref
())
}
}
pub
impl
<
A
>
Future
<
A
>
{
#[cfg(stage0)]
fn
get_ref
<
'a
>
(
&
'a
self
)
->
&
'a
A
{
/*!
* Executes the future's closure and then returns a borrowed
...
...
@@ -61,19 +62,53 @@ fn get_ref<'a>(&'a self) -> &'a A {
* the future.
*/
unsafe
{
{
match
self
.state
{
Forced
(
ref
mut
v
)
=>
{
return
cast
::
transmute
(
v
);
}
Evaluating
=>
fail
!
(
~
"Recursive forcing of future!"
),
Pending
(
_
)
=>
{}
}
}
{
let
mut
state
=
Evaluating
;
self
.state
<->
state
;
match
state
{
Forced
(
_
)
|
Evaluating
=>
fail
!
(
~
"Logic error."
),
Pending
(
f
)
=>
{
self
.state
=
Forced
(
f
());
cast
::
transmute
(
self
.get_ref
())
}
}
}
}
}
#[cfg(stage1)]
#[cfg(stage2)]
#[cfg(stage3)]
fn
get_ref
<
'a
>
(
&
'a
mut
self
)
->
&
'a
A
{
/*!
* Executes the future's closure and then returns a borrowed
* pointer to the result. The borrowed pointer lasts as long as
* the future.
*/
unsafe
{
{
match
self
.state
{
Forced
(
ref
mut
v
)
=>
{
return
cast
::
transmute
(
v
);
}
Evaluating
=>
fail
!
(
~
"Recursive forcing of future!"
),
Pending
(
_
)
=>
{}
}
}
{
let
mut
state
=
Evaluating
;
self
.state
<->
state
;
match
state
{
Forced
(
_
)
|
Evaluating
=>
fail
!
(
~
"Logic error."
),
Pending
(
f
)
=>
{
self
.state
=
Forced
(
f
());
self
.get_ref
()
cast
::
transmute
(
self
.get_ref
())
}
}
}
}
...
...
@@ -150,7 +185,7 @@ mod test {
#[test]
fn
test_from_value
()
{
let
f
=
from_value
(
~
"snail"
);
let
mut
f
=
from_value
(
~
"snail"
);
assert
!
(
f
.get
()
==
~
"snail"
);
}
...
...
@@ -158,31 +193,31 @@ fn test_from_value() {
fn
test_from_port
()
{
let
(
po
,
ch
)
=
oneshot
();
send_one
(
ch
,
~
"whale"
);
let
f
=
from_port
(
po
);
let
mut
f
=
from_port
(
po
);
assert
!
(
f
.get
()
==
~
"whale"
);
}
#[test]
fn
test_from_fn
()
{
let
f
=
from_fn
(||
~
"brail"
);
let
mut
f
=
from_fn
(||
~
"brail"
);
assert
!
(
f
.get
()
==
~
"brail"
);
}
#[test]
fn
test_interface_get
()
{
let
f
=
from_value
(
~
"fail"
);
let
mut
f
=
from_value
(
~
"fail"
);
assert
!
(
f
.get
()
==
~
"fail"
);
}
#[test]
fn
test_get_ref_method
()
{
let
f
=
from_value
(
22
);
let
mut
f
=
from_value
(
22
);
assert
!
(
*
f
.get_ref
()
==
22
);
}
#[test]
fn
test_spawn
()
{
let
f
=
spawn
(||
~
"bale"
);
let
mut
f
=
spawn
(||
~
"bale"
);
assert
!
(
f
.get
()
==
~
"bale"
);
}
...
...
@@ -190,14 +225,14 @@ fn test_spawn() {
#[should_fail]
#[ignore(cfg(target_os
=
"win32"
))]
fn
test_futurefail
()
{
let
f
=
spawn
(||
fail
!
());
let
mut
f
=
spawn
(||
fail
!
());
let
_
x
:
~
str
=
f
.get
();
}
#[test]
fn
test_sendable_future
()
{
let
expected
=
~
"schlorf"
;
let
f
=
do
spawn
{
copy
expected
};
let
mut
f
=
do
spawn
{
copy
expected
};
do
task
::
spawn
||
{
let
actual
=
f
.get
();
assert
!
(
actual
==
expected
);
...
...
src/libstd/par.rs
浏览文件 @
bba0680c
...
...
@@ -73,10 +73,10 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>(
info!
(
"num_tasks: %?"
,
(
num_tasks
,
futures
.len
()));
assert
!
((
num_tasks
==
futures
.len
()));
let
r
=
do
futures
.map
()
|
ys
|
{
let
r
=
do
vec
::
map_consume
(
futures
)
|
ys
|
{
let
mut
ys
=
ys
;
ys
.get
()
};
assert
!
((
r
.len
()
==
futures
.len
()));
r
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录