- 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.
推薦閱讀
- 區(qū)塊鏈在電子檔案管理中的應(yīng)用
- 大數(shù)據(jù)環(huán)境下圖書館文獻(xiàn)信息資源建設(shè)與利用
- 專業(yè)圖書館發(fā)展之道
- 智慧場館與智慧學(xué)習(xí)
- 圖書館學(xué)是什么
- 面向青少年的博物館教育(上下卷)
- 文獻(xiàn)保護(hù)中英雙解詞語手冊
- 中國城市遺址類博物館開發(fā)模式研究
- 河南省博物院鎮(zhèn)館之寶
- 北京大學(xué)中國古文獻(xiàn)研究中心集刊·第十四輯
- 邂逅法學(xué)圖書館:浙江大學(xué)光華法學(xué)院師生原創(chuàng)文集
- 守望與思索:人文清華講壇實錄III
- 魯迅輯校古籍考
- 圖書館學(xué)基礎(chǔ)簡明教程
- 高校圖書館建設(shè)與知識管理