diff --git a/exercise/exercises/enums/README.md b/exercise/exercises/enums/README.md index 30d4d91d..a3603be1 100644 --- a/exercise/exercises/enums/README.md +++ b/exercise/exercises/enums/README.md @@ -1,10 +1,11 @@ -# Enums +# 枚举(enums) -Rust allows you to define types called "enums" which enumerate possible values. -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. +Rust 有一种叫做“枚举”的类型,这种类型列举出了某种集合中所有可能的值。 +枚举是许多语言共有的一个功能,但它的作用在每种语言中都有所不同。 +如 F#、OCaml 和 Haskell 之类的函数式语言中的代数数据类型(algebraic data types)和 Rust 的枚举很相似。 +Rust 的“模式匹配”功能与枚举结合起非常强大,利用它我们很容易就能针对枚举的不同类型运行不同的代码。 -## Further information +## 更多信息 - [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html) - [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html) diff --git a/exercise/exercises/enums/enums1.rs b/exercise/exercises/enums/enums1.rs index a2223d33..1cc15cad 100644 --- a/exercise/exercises/enums/enums1.rs +++ b/exercise/exercises/enums/enums1.rs @@ -1,11 +1,11 @@ // enums1.rs -// Make me compile! Execute `rustlings hint enums1` for hints! +// 让我能够编译!执行 `rustex hint enums1` 获取提示 :) // I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define a few types of messages as used below + // TODO:遵照下面的使用方式来定义几种 Message 的类型 } fn main() { diff --git a/exercise/exercises/enums/enums2.rs b/exercise/exercises/enums/enums2.rs index ec32d952..eac3f5e4 100644 --- a/exercise/exercises/enums/enums2.rs +++ b/exercise/exercises/enums/enums2.rs @@ -1,11 +1,11 @@ // enums2.rs -// Make me compile! Execute `rustlings hint enums2` for hints! +// 让我能够编译!执行 `rustex hint enums2` 获取提示! // I AM NOT DONE #[derive(Debug)] enum Message { - // TODO: define the different variants used below + // TODO:定义下面使用到的多种 Message 类型 } impl Message { diff --git a/exercise/exercises/enums/enums3.rs b/exercise/exercises/enums/enums3.rs index 178b40c4..88087d6e 100644 --- a/exercise/exercises/enums/enums3.rs +++ b/exercise/exercises/enums/enums3.rs @@ -1,10 +1,10 @@ // enums3.rs -// Address all the TODOs to make the tests pass! +// 解决所有的 TODO ,通过测试! // I AM NOT DONE enum Message { - // TODO: implement the message variant types based on their usage below + // TODO:根据以下的使用方式,实现 Message 的不同类型 } struct Point { @@ -36,7 +36,7 @@ impl State { } fn process(&mut self, message: Message) { - // TODO: create a match expression to process the different message variants + // TODO:使用 match 表达式来处理不同类型的消息 } } diff --git a/exercise/info.toml b/exercise/info.toml index 63a3615a..7b0c682a 100644 --- a/exercise/info.toml +++ b/exercise/info.toml @@ -309,21 +309,22 @@ name = "enums1" path = "exercises/enums/enums1.rs" mode = "compile" hint = """ -Hint: The declaration of the enumeration type has not been defined yet.""" +提示:枚举类型还没有被定义。""" [[exercises]] name = "enums2" path = "exercises/enums/enums2.rs" mode = "compile" hint = """ -Hint: you can create enumerations that have different variants with different types -such as no data, anonymous structs, a single string, tuples, ...etc""" +提示:你可以创建多种不同类型的枚举,如不包含值、匿名结构*、字符串、元组,等等。 + +译:匿名结构可能是不命名字段名的结构""" [[exercises]] name = "enums3" path = "exercises/enums/enums3.rs" mode = "test" -hint = "No hints this time ;)" +hint = "这次没有提示 ;)" # MODULES