Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8d0be731
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,发现更多精彩内容 >>
提交
8d0be731
编写于
3月 26, 2014
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc: Update the tutorial about bounds for traits
上级
bb9172d7
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
25 addition
and
23 deletion
+25
-23
src/doc/tutorial.md
src/doc/tutorial.md
+17
-15
src/libnative/io/file_win32.rs
src/libnative/io/file_win32.rs
+2
-2
src/libnative/io/pipe_win32.rs
src/libnative/io/pipe_win32.rs
+6
-6
未找到文件。
src/doc/tutorial.md
浏览文件 @
8d0be731
...
...
@@ -2430,23 +2430,25 @@ select the method to call at runtime.
This usage of traits is similar to Java interfaces.
By default, each of the three storage classes for traits enforce a
particular set of built-in kinds that their contents must fulfill in
order to be packaged up in a trait object of that storage class.
*
The contents of owned traits (
`~Trait`
) must fulfill the
`Send`
bound.
*
The contents of reference traits (
`&Trait`
) are not constrained by any bound.
Consequently, the trait objects themselves automatically fulfill their
respective kind bounds. However, this default behavior can be overridden by
specifying a list of bounds on the trait type, for example, by writing
`~Trait:`
(which indicates that the contents of the owned trait need not fulfill any
bounds), or by writing
`~Trait:Send+Share`
, which indicates that in addition
to fulfilling
`Send`
, contents must also fulfill
`Share`
, and as a consequence,
the trait itself fulfills
`Share`
.
*
`~Trait:Send`
is equivalent to
`~Trait`
.
*
`&Trait:`
is equivalent to
`&Trait`
.
There are some built-in bounds, such as
`Send`
and
`Share`
, which are properties
of the components of types. By design, trait objects don't know the exact type
of their contents and so the compiler cannot reason about those properties.
You can instruct the compiler, however, that the contents of a trait object must
acribe to a particular bound with a trailing colon (
`:`
). These are examples of
valid types:
~~~
rust
trait
Foo
{}
trait
Bar
<
T
>
{}
fn
sendable_foo
(
f
:
~
Foo
:
Send
)
{
/* ... */
}
fn
shareable_bar
<
T
:
Share
>
(
b
:
&
Bar
<
T
>
:
Share
)
{
/* ... */
}
~~~
When no colon is specified (such as the type
`~Foo`
), it is inferred that the
value ascribes to no bounds. They must be added manually if any bounds are
necessary for usage.
Builtin kind bounds can also be specified on closure types in the same way (for
example, by writing
`fn:Send()`
), and the default behaviours are the same as
...
...
src/libnative/io/file_win32.rs
浏览文件 @
8d0be731
...
...
@@ -206,8 +206,8 @@ fn read(&mut self, buf: &mut [u8]) -> Result<uint, IoError> {
fn
write
(
&
mut
self
,
buf
:
&
[
u8
])
->
Result
<
(),
IoError
>
{
self
.inner_write
(
buf
)
}
fn
clone
(
&
self
)
->
~
rtio
::
RtioPipe
{
~
FileDesc
{
inner
:
self
.inner
.clone
()
}
as
~
rtio
::
RtioPipe
fn
clone
(
&
self
)
->
~
rtio
::
RtioPipe
:
Send
{
~
FileDesc
{
inner
:
self
.inner
.clone
()
}
as
~
rtio
::
RtioPipe
:
Send
}
}
...
...
src/libnative/io/pipe_win32.rs
浏览文件 @
8d0be731
...
...
@@ -335,12 +335,12 @@ fn write(&mut self, buf: &[u8]) -> IoResult<()> {
Ok
(())
}
fn
clone
(
&
self
)
->
~
rtio
::
RtioPipe
{
fn
clone
(
&
self
)
->
~
rtio
::
RtioPipe
:
Send
{
~
UnixStream
{
inner
:
self
.inner
.clone
(),
read
:
None
,
write
:
None
,
}
as
~
rtio
::
RtioPipe
}
as
~
rtio
::
RtioPipe
:
Send
}
}
...
...
@@ -383,8 +383,8 @@ fn drop(&mut self) {
}
impl
rtio
::
RtioUnixListener
for
UnixListener
{
fn
listen
(
~
self
)
->
IoResult
<~
rtio
::
RtioUnixAcceptor
>
{
self
.native_listen
()
.map
(|
a
|
~
a
as
~
rtio
::
RtioUnixAcceptor
)
fn
listen
(
~
self
)
->
IoResult
<~
rtio
::
RtioUnixAcceptor
:
Send
>
{
self
.native_listen
()
.map
(|
a
|
~
a
as
~
rtio
::
RtioUnixAcceptor
:
Send
)
}
}
...
...
@@ -485,8 +485,8 @@ pub fn native_accept(&mut self) -> IoResult<UnixStream> {
}
impl
rtio
::
RtioUnixAcceptor
for
UnixAcceptor
{
fn
accept
(
&
mut
self
)
->
IoResult
<~
rtio
::
RtioPipe
>
{
self
.native_accept
()
.map
(|
s
|
~
s
as
~
rtio
::
RtioPipe
)
fn
accept
(
&
mut
self
)
->
IoResult
<~
rtio
::
RtioPipe
:
Send
>
{
self
.native_accept
()
.map
(|
s
|
~
s
as
~
rtio
::
RtioPipe
:
Send
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录