- 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.
推薦閱讀
- JavaScript百煉成仙
- SOA實(shí)踐
- Mastering QGIS
- Python機(jī)器學(xué)習(xí)算法與實(shí)戰(zhàn)
- Python算法從菜鳥到達(dá)人
- 用戶體驗(yàn)增長:數(shù)字化·智能化·綠色化
- 劍指Java:核心原理與應(yīng)用實(shí)踐
- Mastering ArcGIS Enterprise Administration
- Solutions Architect's Handbook
- R Data Science Essentials
- 深入理解BootLoader
- jQuery技術(shù)內(nèi)幕:深入解析jQuery架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)原理
- HTML+CSS+JavaScript網(wǎng)頁制作:從入門到精通(第4版)
- SQL Server on Linux
- PHP Microservices