Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
37bb6ed3
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,发现更多精彩内容 >>
提交
37bb6ed3
编写于
7月 21, 2014
作者:
P
P1start
提交者:
Alex Crichton
7月 21, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clarify the std::vec::Vec docs regarding capacity
上级
36e1f2db
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
3 deletion
+37
-3
src/libcollections/vec.rs
src/libcollections/vec.rs
+37
-3
未找到文件。
src/libcollections/vec.rs
浏览文件 @
37bb6ed3
...
...
@@ -51,10 +51,27 @@
/// The `vec!` macro is provided to make initialization more convenient:
///
/// ```rust
/// let mut vec = vec!
(1i, 2i, 3i)
;
/// let mut vec = vec!
[1i, 2i, 3i]
;
/// vec.push(4);
/// assert_eq!(vec, vec!
(1, 2, 3, 4)
);
/// assert_eq!(vec, vec!
[1, 2, 3, 4]
);
/// ```
///
/// # Capacity and reallocation
///
/// The capacity of a vector is the amount of space allocated for any future
/// elements that will be added onto the vector. This is not to be confused
/// with the *length* of a vector, which specifies the number of actual
/// elements within the vector. If a vector's length exceeds its capacity,
/// its capacity will automatically be increased, but its elements will
/// have to be reallocated.
///
/// For example, a vector with capacity 10 and length 0 would be an empty
/// vector with space for 10 more elements. Pushing 10 or fewer elements onto
/// the vector will not change its capacity or cause reallocation to occur.
/// However, if the vector's length is increased to 11, it will have to
/// reallocate, which can be slow. For this reason, it is recommended
/// to use `Vec::with_capacity` whenever possible to specify how big the vector
/// is expected to get.
#[unsafe_no_drop_flag]
pub
struct
Vec
<
T
>
{
len
:
uint
,
...
...
@@ -87,11 +104,28 @@ pub fn new() -> Vec<T> {
/// The vector will be able to hold exactly `capacity` elements without
/// reallocating. If `capacity` is 0, the vector will not allocate.
///
/// It is important to note that this function does not specify the
/// *length* of the returned vector, but only the *capacity*. (For an
/// explanation of the difference between length and capacity, see
/// the main `Vec` docs above, 'Capacity and reallocation'.) To create
/// a vector of a given length, use `Vec::from_elem` or `Vec::from_fn`.
///
/// # Example
///
/// ```rust
/// # use std::vec::Vec;
/// let vec: Vec<int> = Vec::with_capacity(10);
/// let mut vec: Vec<int> = Vec::with_capacity(10);
///
/// // The vector contains no items, even though it has capacity for more
/// assert_eq!(vec.len(), 0);
///
/// // These are all done without reallocating...
/// for i in range(0u, 10) {
/// vec.push(i);
/// }
///
/// // ...but this may make the vector reallocate
/// vec.push(11);
/// ```
#[inline]
pub
fn
with_capacity
(
capacity
:
uint
)
->
Vec
<
T
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录