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

  • 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.

主站蜘蛛池模板: 江山市| 乌鲁木齐县| 江门市| 桃江县| 和龙市| 东宁县| 措美县| 景德镇市| 蓬溪县| 宁德市| 万山特区| 论坛| 普兰店市| 二连浩特市| 黄浦区| 沂水县| 商丘市| 阳信县| 莱阳市| 涞水县| 长兴县| 彩票| 长武县| 贵溪市| 灌南县| 环江| 宜良县| 高邮市| 兴文县| 东港市| 丹寨县| 扶余县| 钦州市| 古交市| 万宁市| 和田市| 鄄城县| 紫阳县| 沧源| 建始县| 聂拉木县|