- 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.
推薦閱讀
- Vue.js設(shè)計(jì)與實(shí)現(xiàn)
- Getting Started with Gulp(Second Edition)
- Learn Type:Driven Development
- Clojure for Domain:specific Languages
- Data Analysis with IBM SPSS Statistics
- Apache Mesos Essentials
- C語(yǔ)言程序設(shè)計(jì)同步訓(xùn)練與上機(jī)指導(dǎo)(第三版)
- Scientific Computing with Scala
- Windows內(nèi)核編程
- Keras深度學(xué)習(xí)實(shí)戰(zhàn)
- Django 5企業(yè)級(jí)Web應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)(視頻教學(xué)版)
- Scala Functional Programming Patterns
- R語(yǔ)言數(shù)據(jù)挖掘:實(shí)用項(xiàng)目解析
- PowerDesigner 16 從入門(mén)到精通
- SaaS攻略:入門(mén)、實(shí)戰(zhàn)與進(jìn)階