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

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

主站蜘蛛池模板: 荆州市| 高碑店市| 黔西| 隆化县| 麻栗坡县| 新化县| 营口市| 施秉县| 巴东县| 苏尼特右旗| 霞浦县| 宜兴市| 铜陵市| 萨迦县| 确山县| 济南市| 越西县| 北票市| 句容市| 定陶县| 汨罗市| 毕节市| 弥渡县| 盐城市| 牙克石市| 阿拉善盟| 祁连县| 桐梓县| 曲水县| 阳春市| 漳浦县| 陵川县| 临安市| 五台县| 林西县| 安阳县| 准格尔旗| 本溪| 九龙县| 灌云县| 南华县|