Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4dbd10a7
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,发现更多精彩内容 >>
提交
4dbd10a7
编写于
6月 20, 2012
作者:
E
Eric Holk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
First example of a program using pipes.
上级
117b9a0b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
112 addition
and
2 deletion
+112
-2
src/libcore/vec.rs
src/libcore/vec.rs
+2
-2
src/test/run-pass/pipe-manual-1.rs
src/test/run-pass/pipe-manual-1.rs
+110
-0
未找到文件。
src/libcore/vec.rs
浏览文件 @
4dbd10a7
...
...
@@ -1162,14 +1162,14 @@ fn as_mut_buf<E,T>(v: &[mut E], f: fn(*mut E) -> T) -> T {
impl
extensions
<
T
:
copy
>
for
~
[
T
]
{
#[inline(always)]
pure
fn
+
(
rhs
:
&
[
T
])
->
~
[
T
]
{
pure
fn
+
(
rhs
:
&
[
const
T
])
->
~
[
T
]
{
append
(
self
,
rhs
)
}
}
impl
extensions
<
T
:
copy
>
for
~
[
mut
T
]
{
#[inline(always)]
pure
fn
+
(
rhs
:
&
[
mu
t
T
])
->
~
[
mut
T
]
{
pure
fn
+
(
rhs
:
&
[
cons
t
T
])
->
~
[
mut
T
]
{
append_mut
(
self
,
rhs
)
}
}
...
...
src/test/run-pass/pipe-manual-1.rs
0 → 100644
浏览文件 @
4dbd10a7
/*
The first test case using pipes. The idea is to break this into
several stages for prototyping. Here's the plan:
1. Write an already-compiled protocol using existing ports and chans.
2. Take the already-compiled version and add the low-level
synchronization code instead.
3. Write a syntax extension to compile the protocols.
At some point, we'll need to add support for select.
*/
mod
pingpong
{
import
newcomm
::
*
;
type
pingpong
=
~
mut
option
<
(
chan
<
()
>
,
port
<
()
>
)
>
;
fn
init
()
->
(
client
::
ping
,
server
::
ping
)
{
let
cp
=
port
();
let
sp
=
port
();
let
cc
=
chan
(
sp
);
let
sc
=
chan
(
cp
);
let
client
=
client
::
ping
(
~
mut
some
((
cc
,
cp
)));
let
server
=
server
::
ping
(
~
mut
some
((
sc
,
sp
)));
(
client
,
server
)
}
mod
client
{
enum
ping
=
pingpong
;
enum
pong
=
pingpong
;
fn
do_ping
(
-
c
:
ping
)
->
pong
{
let
mut
op
=
none
;
op
<->
**
c
;
let
(
c
,
s
)
<-
option
::
unwrap
(
op
);
c
.send
(());
let
p
<-
(
c
,
s
);
pong
(
~
mut
some
(
p
))
}
fn
do_pong
(
-
c
:
pong
)
->
(
ping
,
())
{
let
mut
op
=
none
;
op
<->
**
c
;
let
(
c
,
s
)
<-
option
::
unwrap
(
op
);
let
d
=
s
.recv
();
let
p
<-
(
c
,
s
);
(
ping
(
~
mut
some
(
p
)),
d
)
}
}
mod
server
{
enum
ping
=
pingpong
;
enum
pong
=
pingpong
;
fn
do_ping
(
-
c
:
ping
)
->
(
pong
,
())
{
let
mut
op
=
none
;
op
<->
**
c
;
let
(
c
,
s
)
<-
option
::
unwrap
(
op
);
let
d
=
s
.recv
();
let
p
<-
(
c
,
s
);
(
pong
(
~
mut
some
(
p
)),
d
)
}
fn
do_pong
(
-
c
:
pong
)
->
ping
{
let
mut
op
=
none
;
op
<->
**
c
;
let
(
c
,
s
)
<-
option
::
unwrap
(
op
);
c
.send
(());
let
p
<-
(
c
,
s
);
ping
(
~
mut
some
(
p
))
}
}
}
fn
client
(
-
chan
:
pingpong
::
client
::
ping
)
{
let
chan
=
pingpong
::
client
::
do_ping
(
chan
);
log
(
error
,
"Sent ping"
);
let
(
_
chan
,
_
data
)
=
pingpong
::
client
::
do_pong
(
chan
);
log
(
error
,
"Received pong"
);
}
fn
server
(
-
chan
:
pingpong
::
server
::
ping
)
{
let
(
chan
,
_
data
)
=
pingpong
::
server
::
do_ping
(
chan
);
log
(
error
,
"Received ping"
);
let
_
chan
=
pingpong
::
server
::
do_pong
(
chan
);
log
(
error
,
"Sent pong"
);
}
fn
main
()
{
let
(
client_
,
server_
)
=
pingpong
::
init
();
let
client_
=
~
mut
some
(
client_
);
let
server_
=
~
mut
some
(
server_
);
task
::
spawn
{|
move
client_
|
let
mut
client__
=
none
;
*
client_
<->
client__
;
client
(
option
::
unwrap
(
client__
));
};
task
::
spawn
{|
move
server_
|
let
mut
server_
ˊ
=
none
;
*
server_
<->
server_
ˊ
;
server
(
option
::
unwrap
(
server_
ˊ
));
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录