|
|
@ -1,10 +1,11 @@
|
|
|
|
# Enums
|
|
|
|
# 枚举(enums)
|
|
|
|
|
|
|
|
|
|
|
|
Rust allows you to define types called "enums" which enumerate possible values.
|
|
|
|
Rust 有一种叫做“枚举”的类型,这种类型列举出了某种集合中所有可能的值。
|
|
|
|
Enums are a feature in many languages, but their capabilities differ in each language. Rust’s enums are most similar to algebraic data types in functional languages, such as F#, OCaml, and Haskell.
|
|
|
|
枚举是许多语言共有的一个功能,但它的作用在每种语言中都有所不同。
|
|
|
|
Useful in combination with enums is Rust's "pattern matching" facility, which makes it easy to run different code for different values of an enumeration.
|
|
|
|
如 F#、OCaml 和 Haskell 之类的函数式语言中的代数数据类型(algebraic data types)和 Rust 的枚举很相似。
|
|
|
|
|
|
|
|
Rust 的“模式匹配”功能与枚举结合起非常强大,利用它我们很容易就能针对枚举的不同类型运行不同的代码。
|
|
|
|
|
|
|
|
|
|
|
|
## Further information
|
|
|
|
## 更多信息
|
|
|
|
|
|
|
|
|
|
|
|
- [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html)
|
|
|
|
- [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html)
|
|
|
|
- [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html)
|
|
|
|
- [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html)
|
|
|
|