知识卡片

普通读书笔记卡 · 6074.f.1.e · 生成模型:未记录

向量连续存储同类值

理解等级:初级

Vec 用一段连续存储保存可增长的同类型元素。T 是这一整组元素的类型,初始内容或以后插入的数据可帮助编译器推断它。若没有线索,空向量需要写出类型。允许追加时用可变绑定,再经 push 放入元素。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《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.