書名: Rust Programming By Example作者名: Guillaume Gomez Antoni Boucher本章字?jǐn)?shù): 109字更新時間: 2021-07-02 19:12:59
Enumerations
While a structure allows us to get multiple values under the same variable, enumerations allow us to choose one value from different types of values.
For example, let's write a type representing an expression:
enum Expr { Null, Add(i32, i32), Sub(i32, i32), Mul(i32, i32), Div { pidend: i32, pisor: i32 }, Val(i32), } let quotient = Expr::Div { pidend: 10, pisor: 2 }; let sum = Expr::Add(40, 2);
The Null variant does not have a value associated with it, Val has one associated value, and Add has two. Div also has two associated values, but they are named, similar to how we define a structure.
推薦閱讀
- 地方檔案與文獻(xiàn)研究(第2輯)
- 情報學(xué)與信息管理的主戰(zhàn)場:北京大學(xué)情報學(xué)與信息管理論壇文集
- 圖書館學(xué)是什么
- 書事:近現(xiàn)代版本雜談
- ??睂W(xué)大綱
- 文件、信息商業(yè)化服務(wù)機(jī)構(gòu)建設(shè)研究
- 中國城市遺址類博物館開發(fā)模式研究
- 圖書館服務(wù)思維研究
- 科學(xué)名家
- 守望與思索:人文清華講壇實錄III
- 基于知識治理的競爭情報協(xié)同模型研究
- 高校圖書館工具書管理與服務(wù)研究
- 中國人民大學(xué)復(fù)印報刊資料轉(zhuǎn)載指數(shù)排名研究報告2018(中國人民大學(xué)研究報告系列)
- 茶與咖啡:張信剛文化與經(jīng)濟(jì)講座
- 抗戰(zhàn)時期中國圖書館界研究