- 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.
推薦閱讀
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- Python自然語言處理實(shí)戰(zhàn):核心技術(shù)與算法
- Learning Bayesian Models with R
- 深度強(qiáng)化學(xué)習(xí)算法與實(shí)踐:基于PyTorch的實(shí)現(xiàn)
- 人人都是網(wǎng)站分析師:從分析師的視角理解網(wǎng)站和解讀數(shù)據(jù)
- Mathematica Data Analysis
- RabbitMQ Cookbook
- Instant Ext.NET Application Development
- 用戶體驗(yàn)可視化指南
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- 零基礎(chǔ)學(xué)C語言第2版
- Data Science Algorithms in a Week
- OpenCV Android開發(fā)實(shí)戰(zhàn)
- .NET 4.0面向?qū)ο缶幊搪劊簯?yīng)用篇
- Visual C++程序設(shè)計(jì)與項(xiàng)目實(shí)踐