Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c05424f2
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,发现更多精彩内容 >>
提交
c05424f2
编写于
9月 13, 2016
作者:
G
Guillaume Gomez
提交者:
GitHub
9月 13, 2016
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #36402 - kmcallister:gh-29331-array-docs, r=GuillaumeGomez
Tweak array docs Fixes #29331. r? @GuillaumeGomez
上级
d6aa4e82
54c680cd
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
65 addition
and
21 deletion
+65
-21
src/libstd/primitive_docs.rs
src/libstd/primitive_docs.rs
+65
-21
未找到文件。
src/libstd/primitive_docs.rs
浏览文件 @
c05424f2
...
@@ -249,37 +249,58 @@ mod prim_pointer { }
...
@@ -249,37 +249,58 @@ mod prim_pointer { }
#[doc(primitive
=
"array"
)]
#[doc(primitive
=
"array"
)]
//
//
/// A fixed-size array, denoted `[T; N]`, for the element type, `T`, and the
/// A fixed-size array, denoted `[T; N]`, for the element type, `T`, and the
/// non-negative compile
time constant size, `N`.
/// non-negative compile
-
time constant size, `N`.
///
///
/// Arrays values are created either with an explicit expression that lists
/// There are two syntactic forms for creating an array:
/// each element: `[x, y, z]` or a repeat expression: `[x; N]`. The repeat
/// expression requires that the element type is `Copy`.
///
///
/// The type `[T; N]` is `Copy` if `T: Copy`.
/// * A list with each element, i.e. `[x, y, z]`.
/// * A repeat expression `[x; N]`, which produces an array with `N` copies of `x`.
/// The type of `x` must be [`Copy`][copy].
///
///
/// Arrays of sizes from 0 to 32 (inclusive) implement the following traits if
/// Arrays of sizes from 0 to 32 (inclusive) implement the following traits if
/// the element type allows it:
/// the element type allows it:
///
///
/// -
`Clone`
(only if `T: Copy`)
/// -
[`Clone`][clone]
(only if `T: Copy`)
/// -
`Debug`
/// -
[`Debug`][debug]
/// -
`IntoIterator`
(implemented for `&[T; N]` and `&mut [T; N]`)
/// -
[`IntoIterator`][intoiterator]
(implemented for `&[T; N]` and `&mut [T; N]`)
/// -
`PartialEq`, `PartialOrd`, `Ord`, `Eq`
/// -
[`PartialEq`][partialeq], [`PartialOrd`][partialord], [`Eq`][eq], [`Ord`][ord]
/// -
`Hash`
/// -
[`Hash`][hash]
/// -
`AsRef`, `AsMut`
/// -
[`AsRef`][asref], [`AsMut`][asmut]
/// -
`Borrow`, `BorrowMut`
/// -
[`Borrow`][borrow], [`BorrowMut`][borrowmut]
/// -
`Default`
/// -
[`Default`][default]
///
///
/// This limitation
to `N in 0..33
` exists because Rust does not yet support
/// This limitation
on the size `N
` exists because Rust does not yet support
///
generics over the size of an array type. `[Foo; 3]` and `[Bar; 3]` are
///
code that is generic over the size of an array type. `[Foo; 3]` and `[Bar; 3]`
/// instances of same generic type `[T; 3]`, but `[Foo; 3]` and `[Foo; 5]` are
///
are
instances of same generic type `[T; 3]`, but `[Foo; 3]` and `[Foo; 5]` are
/// entirely different types. As a stopgap, trait implementations are
/// entirely different types. As a stopgap, trait implementations are
/// statically generated
for `N in 0..33`
.
/// statically generated
up to size 32
.
///
///
/// Arrays coerce to [slices (`[T]`)][slice], so their methods can be called on
/// Arrays of *any* size are [`Copy`][copy] if the element type is `Copy`. This
/// arrays. Slices are dynamic and do not coerce to arrays; consequently more
/// works because the `Copy` trait is specially known to the compiler.
/// methods are defined on `slice` where they support both types.
///
/// Arrays coerce to [slices (`[T]`)][slice], so a slice method may be called on
/// an array. Indeed, this provides most of the API for working with arrays.
/// Slices have a dynamic size and do not coerce to arrays.
///
/// There is no way to move elements out of an array. See [`mem::replace`][replace]
/// for an alternative.
///
///
/// [slice]: primitive.slice.html
/// [slice]: primitive.slice.html
/// [copy]: marker/trait.Copy.html
/// [clone]: clone/trait.Clone.html
/// [debug]: fmt/trait.Debug.html
/// [intoiterator]: iter/trait.IntoIterator.html
/// [partialeq]: cmp/trait.PartialEq.html
/// [partialord]: cmp/trait.PartialOrd.html
/// [eq]: cmp/trait.Eq.html
/// [ord]: cmp/trait.Ord.html
/// [hash]: hash/trait.Hash.html
/// [asref]: convert/trait.AsRef.html
/// [asmut]: convert/trait.AsMut.html
/// [borrow]: borrow/trait.Borrow.html
/// [borrowmut]: borrow/trait.BorrowMut.html
/// [default]: default/trait.Default.html
/// [replace]: mem/fn.replace.html
///
///
/// # Examples
/// # Examples
///
///
...
@@ -295,7 +316,30 @@ mod prim_pointer { }
...
@@ -295,7 +316,30 @@ mod prim_pointer { }
/// for x in &array {
/// for x in &array {
/// print!("{} ", x);
/// print!("{} ", x);
/// }
/// }
/// ```
///
/// An array itself is not iterable:
///
/// ```ignore
/// let array: [i32; 3] = [0; 3];
///
/// for x in array { }
/// // error: the trait bound `[i32; 3]: std::iter::Iterator` is not satisfied
/// ```
///
///
/// The solution is to coerce the array to a slice by calling a slice method:
///
/// ```
/// # let array: [i32; 3] = [0; 3];
/// for x in array.iter() { }
/// ```
///
/// If the array has 32 or fewer elements (see above), you can also use the
/// array reference's `IntoIterator` implementation:
///
/// ```
/// # let array: [i32; 3] = [0; 3];
/// for x in &array { }
/// ```
/// ```
///
///
mod
prim_array
{
}
mod
prim_array
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录