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

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.

主站蜘蛛池模板: 荣成市| 柞水县| 峨眉山市| 辽阳市| 乌鲁木齐市| 工布江达县| 天台县| 绍兴市| 庆元县| 新津县| 镇赉县| 会昌县| 滦南县| 历史| 崇文区| 宁化县| 富裕县| 阿坝| 松桃| 都安| 仲巴县| 清丰县| 灵丘县| 肇东市| 宜宾市| 南江县| 金溪县| 顺义区| 浙江省| 安平县| 工布江达县| 保康县| 广元市| 汤阴县| 封开县| 拉萨市| 海口市| 鸡西市| 容城县| 余姚市| 深圳市|