← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 10503.c.2 · 生成模型:未记录

向量的创建与遍历

理解等级:初级

Vec<T> 表示运行时可增长的同类型元素序列。已知初值时用 vec![2, 3, 5],已知运行时长度及填充值时用 vec![0; rows * cols],逐步追加可从 Vec::new() 开始。已有迭代器可写 let v: Vec<i32> = (0..5).collect(),用注解选定结果容器。for item in v 可依次取出元素。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|动态向量的构造、容量与更新,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#vectors` - 结论依据:原文用字面式宏、空容器逐项 push、collect 及 for 循环说明构造与使用。 - 原始内容:You’ll often need to supply the type when using collect (as we’ve done here), because it can build many different sorts of collections, not just