官术网_书友最值得收藏!

  • Learning Rust
  • Paul Johnson Vesa Kaihlavirta
  • 83字
  • 2021-07-02 23:07:18

Creating a vector via an iterator

Another way to create a vector is via an iterator. This is achieved via the collect() method:

let my_vec: Vec<u64> = (0..10).collect(); 

The format for the iterator is very convenient. Instead of the likes of let foo = {0,1,2,3};, this is shortened to use .., which means all numbers between a and b (b being excluded - so 0 .. 10 creates a vector containing 0,1,2,3,4,5,6,7,8,9). This can be seen in the source example supplied with this book.

主站蜘蛛池模板: 确山县| 英超| 高淳县| 黄平县| 柯坪县| 金溪县| 周宁县| 开鲁县| 叶城县| 禹州市| 迁安市| 江达县| 白城市| 师宗县| 炎陵县| 通河县| 札达县| 德兴市| 勐海县| 康平县| 肇州县| 始兴县| 酉阳| 河南省| 永胜县| 西宁市| 张家港市| 遂宁市| 乐都县| 阳城县| 长沙县| 漯河市| 炎陵县| 佛冈县| 大悟县| 稻城县| 县级市| 南郑县| 平舆县| 临朐县| 桂阳县|