- Rust Programming By Example
- Guillaume Gomez Antoni Boucher
- 119字
- 2021-07-02 19:12:58
Tuples
Tuples and structures are similar, except that tuples' fields are unnamed. Tuples are declared inside parentheses, with the element separated by a comma:
let tuple = (24, 42); println!("({}, {})", tuple.0, tuple.1);
As you can see on the second line, we can access the elements of a tuple with .index, where index is a constant and this index starts at 0.
Tuples can be used to return multiple values from a function. For instance, the str::split_at() method returns two strings:
let (hello, world) = "helloworld".split_at(5); println!("{}, {}!", hello, world);
Here, we assign the two elements of the tuple to the hello and world variables. We'll see why this works in the Pattern matching section.
推薦閱讀
- 專業(yè)圖書館發(fā)展之道
- 校勘學(xué)大綱
- 國外圖書館動漫資源建設(shè)與服務(wù)
- 知中8·了不起的宋版書
- 檔案檢索: 理論與方法
- 醫(yī)藥信息處理與分析
- 檔案智慧化管理與開發(fā)利用的探索研究
- 移動社交時代的電子閱讀
- 檔案修復(fù)與歷史資料的數(shù)字化:第六屆東亞史料研究編纂機構(gòu)聯(lián)席會議論文集
- 圖書館戰(zhàn)略規(guī)劃研究
- 中國圖書館轉(zhuǎn)型風(fēng)險研究
- 檔案與少數(shù)民族記憶
- 且為繁華寄書香:高校圖書館閱讀推廣理論與實務(wù)
- 黨校圖書館轉(zhuǎn)型發(fā)展實踐研究
- Practical Mobile Forensics(Third Edition)