知识卡片
向量连续存储同类值
Vec 用一段连续存储保存可增长的同类型元素。T 是这一整组元素的类型,初始内容或以后插入的数据可帮助编译器推断它。若没有线索,空向量需要写出类型。允许追加时用可变绑定,再经 push 放入元素。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 常用集合 Storing Lists of Values with Vectors · 查看原书依据
The first collection type we’ll look at is Vec<T>, also known as a vector. Vectors allow you to store more than one value in a single data structure that puts all the values next to each other in memory. Vectors can only store values of the same type.
参考来源
- 位置:《The Rust Programming Language(第2版)》第08章 常用集合(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c08.xhtml`,块 0010)
- 结论依据:原文说明 Vec 的连续布局和同类型约束,支撑其与动态顺序列表的对应关系。
- 原始内容:The first collection type we’ll look at is Vec<T>, also known as a vector. Vectors allow you to store more than one value in a single data structure that puts all the values next to each other in memory. Vectors can only store values of the same type.