- 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.
推薦閱讀
- 微服務設計(第2版)
- Google Flutter Mobile Development Quick Start Guide
- Android項目開發入門教程
- PHP網絡編程學習筆記
- Responsive Web Design by Example
- Julia高性能科學計算(第2版)
- R語言與網絡輿情處理
- MySQL入門很輕松(微課超值版)
- Spring技術內幕:深入解析Spring架構與設計原理(第2版)
- Python Interviews
- PhoneGap 4 Mobile Application Development Cookbook
- HTML5移動Web開發
- Node.js應用開發
- 大話程序員:從入門到優秀全攻略
- Windows 10 for Enterprise Administrators