diff --git a/exercise/exercises/primitive_types/README.md b/exercise/exercises/primitive_types/README.md index cea69b02..8ff09a7e 100644 --- a/exercise/exercises/primitive_types/README.md +++ b/exercise/exercises/primitive_types/README.md @@ -1,9 +1,8 @@ -# Primitive Types +# 基本类型(Primitive Types) -Rust has a couple of basic types that are directly implemented into the -compiler. In this section, we'll go through the most important ones. +Rust 有几个直接在编译器中实现基本类型。在本节中,我们来看看最重要的几个。 -## Further information +## 更多信息 - [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html) - [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html) diff --git a/exercise/exercises/primitive_types/primitive_types1.rs b/exercise/exercises/primitive_types/primitive_types1.rs index 09121392..2ab9ed61 100644 --- a/exercise/exercises/primitive_types/primitive_types1.rs +++ b/exercise/exercises/primitive_types/primitive_types1.rs @@ -1,6 +1,6 @@ // primitive_types1.rs -// Fill in the rest of the line that has code missing! -// No hints, there's no tricks, just get used to typing these :) +// 补充不完整代码行的缺失部分! +// 没有提示,也没有什么诀窍,只要习惯于键入这些内容就可以了 :) // I AM NOT DONE @@ -9,11 +9,11 @@ fn main() { let is_morning = true; if is_morning { - println!("Good morning!"); + println!("Good morning!");// 译:"早上好" } - let // Finish the rest of this line like the example! Or make it be false! + let // 参照上面的示例来补充这一行的缺失部分!或者让它值为 false ! if is_evening { - println!("Good evening!"); + println!("Good evening!");// 译:"晚上好" } } diff --git a/exercise/exercises/primitive_types/primitive_types2.rs b/exercise/exercises/primitive_types/primitive_types2.rs index 6576a4d5..506ae11e 100644 --- a/exercise/exercises/primitive_types/primitive_types2.rs +++ b/exercise/exercises/primitive_types/primitive_types2.rs @@ -1,6 +1,6 @@ // primitive_types2.rs -// Fill in the rest of the line that has code missing! -// No hints, there's no tricks, just get used to typing these :) +// 补充不完整代码行的缺失部分! +// 没有提示,也没有什么诀窍,只要习惯于键入这些内容就可以了 :) // I AM NOT DONE @@ -9,16 +9,16 @@ fn main() { let my_first_initial = 'C'; if my_first_initial.is_alphabetic() { - println!("Alphabetical!"); + println!("Alphabetical!");// 译:"字母!" } else if my_first_initial.is_numeric() { - println!("Numerical!"); + println!("Numerical!");// 译:"数字!" } else { - println!("Neither alphabetic nor numeric!"); + println!("Neither alphabetic nor numeric!");// 译:"既不是字母也不是数字!" } - let // Finish this line like the example! What's your favorite character? - // Try a letter, try a number, try a special character, try a character - // from a different language than your own, try an emoji! + let // 像上面的示例一样完成这行代码!你最喜欢的角色是什么? + // 试试一个字母,或者一个数字,也可以一个特殊字符,又或者一个不属于 + // 你母语的字符,一个表情符号看起来也不错。 if your_character.is_alphabetic() { println!("Alphabetical!"); } else if your_character.is_numeric() { diff --git a/exercise/exercises/primitive_types/primitive_types3.rs b/exercise/exercises/primitive_types/primitive_types3.rs index aaa518be..9d529db3 100644 --- a/exercise/exercises/primitive_types/primitive_types3.rs +++ b/exercise/exercises/primitive_types/primitive_types3.rs @@ -1,6 +1,6 @@ // primitive_types3.rs -// Create an array with at least 100 elements in it where the ??? is. -// Execute `rustlings hint primitive_types3` for hints! +// 在 ??? 处创建一个不少于 100 个元素的数组。 +// 执行 `rustex hint primitive_types3` 获取提示! // I AM NOT DONE @@ -8,8 +8,8 @@ fn main() { let a = ??? if a.len() >= 100 { - println!("Wow, that's a big array!"); + println!("Wow, that's a big array!");// 译:"哇!那数组可真大!" } else { - println!("Meh, I eat arrays like that for breakfast."); + println!("Meh, I eat arrays like that for breakfast.");// 译:"嗯,我把这样的数组当早餐吃。" } } diff --git a/exercise/exercises/primitive_types/primitive_types4.rs b/exercise/exercises/primitive_types/primitive_types4.rs index 10b553e9..8f102e6d 100644 --- a/exercise/exercises/primitive_types/primitive_types4.rs +++ b/exercise/exercises/primitive_types/primitive_types4.rs @@ -1,6 +1,6 @@ // primitive_types4.rs -// Get a slice out of Array a where the ??? is so that the test passes. -// Execute `rustlings hint primitive_types4` for hints!! +// 在 ??? 处获取数组 a 的一个切片(slice),以通过测试。 +// 执行 `rustex hint primitive_types4` 获取提示!! // I AM NOT DONE diff --git a/exercise/exercises/primitive_types/primitive_types5.rs b/exercise/exercises/primitive_types/primitive_types5.rs index 680d8d23..b5239838 100644 --- a/exercise/exercises/primitive_types/primitive_types5.rs +++ b/exercise/exercises/primitive_types/primitive_types5.rs @@ -1,12 +1,12 @@ // primitive_types5.rs -// Destructure the `cat` tuple so that the println will work. -// Execute `rustlings hint primitive_types5` for hints! +// 对 `cat` 元组进行解构(Destructure),使 println 能够运行。 +// 执行 `rustex hint primitive_types5` 获取提示! // I AM NOT DONE fn main() { let cat = ("Furry McFurson", 3.5); - let /* your pattern here */ = cat; + let /* your pattern here */ = cat;// 译:模式写在这 println!("{} is {} years old.", name, age); } diff --git a/exercise/exercises/primitive_types/primitive_types6.rs b/exercise/exercises/primitive_types/primitive_types6.rs index b8c9b82b..3fdd59b2 100644 --- a/exercise/exercises/primitive_types/primitive_types6.rs +++ b/exercise/exercises/primitive_types/primitive_types6.rs @@ -1,16 +1,16 @@ // primitive_types6.rs -// Use a tuple index to access the second element of `numbers`. -// You can put the expression for the second element where ??? is so that the test passes. -// Execute `rustlings hint primitive_types6` for hints! +// 使用元组索引(tuple index)来访问 `numbers` 的第二个元素。 +// 你可以把第二个元素的表达式放在 ??? 处,这样测试就会通过。 +// 执行 `rustex hint primitive_types6` 获取提示! // I AM NOT DONE #[test] fn indexing_tuple() { let numbers = (1, 2, 3); - // Replace below ??? with the tuple indexing syntax. + // 用元组索引的语法替换下面的 ??? let second = ???; assert_eq!(2, second, - "This is not the 2nd number in the tuple!") + "This is not the 2nd number in the tuple!")// 译:这不是元组中的第二个数字! } diff --git a/exercise/info.toml b/exercise/info.toml index d94f55e2..8b194743 100644 --- a/exercise/info.toml +++ b/exercise/info.toml @@ -212,40 +212,37 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-ref name = "primitive_types1" path = "exercises/primitive_types/primitive_types1.rs" mode = "compile" -hint = "No hints this time ;)" +hint = "这次没有提示 ;)" [[exercises]] name = "primitive_types2" path = "exercises/primitive_types/primitive_types2.rs" mode = "compile" -hint = "No hints this time ;)" +hint = "这次没有提示 ;)" [[exercises]] name = "primitive_types3" path = "exercises/primitive_types/primitive_types3.rs" mode = "compile" hint = """ -There's a shorthand to initialize Arrays with a certain size that does not -require you to type in 100 items (but you certainly can if you want!). -For example, you can do: +有一种简便的方法可以初始化具有一定大小的数组,而不需要你输入 100 个 +元素(但如果你想的话,那当然可以!)。 +例如,你可以这样做: let array = ["Are we there yet?"; 10]; -Bonus: what are some other things you could have that would return true -for `a.len() >= 100`?""" +额外目标: 还有哪些东西可以在 `a.len()>=100` 时返回 true """ [[exercises]] name = "primitive_types4" path = "exercises/primitive_types/primitive_types4.rs" mode = "test" hint = """ -Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book: -https://doc.rust-lang.org/book/ch04-03-slices.html -and use the starting and ending indices of the items in the Array -that you want to end up in the slice. +看看这本书的:Understanding Ownership -> Slices -> Other Slices 章节吧: +https://doc.rust-lang.org/book/ch04-03-slices.html, +然后找出所需切片元素对应数组里的起始和截止下标。 -If you're curious why the first argument of `assert_eq!` does not -have an ampersand for a reference since the second argument is a -reference, take a look at the Deref coercions section of the book: +如果你好奇既然 `assert_eq!` 的第二个参数是引用,为什么第一个参数 +没有使用 & 号用来表示引用,可以看看这本书的 Deref 强制转换部分: https://doc.rust-lang.org/book/ch15-02-deref.html""" [[exercises]] @@ -253,22 +250,20 @@ name = "primitive_types5" path = "exercises/primitive_types/primitive_types5.rs" mode = "compile" hint = """ -Take a look at the Data Types -> The Tuple Type section of the book: +看看这本书的 Data Types -> The Tuple Type 类型章节: https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type -Particularly the part about destructuring (second to last example in the section). -You'll need to make a pattern to bind `name` and `age` to the appropriate parts -of the tuple. You can do it!!""" +特别是关于解构的部分(这节中倒数第二个例子)。 +你需要一个模式将 `name` 和 `age` 绑定到元组的适当部分。你能够做到的!!""" [[exercises]] name = "primitive_types6" path = "exercises/primitive_types/primitive_types6.rs" mode = "test" hint = """ -While you could use a destructuring `let` for the tuple here, try -indexing into it instead, as explained in the last example of the -Data Types -> The Tuple Type section of the book: +虽然你可以使用 `let` 对元组进行解构 ,但不妨试试对它进行索引, +正如这本书的 Data Types -> The Tuple Type 部分的最后一个例子表示的那样。 https://doc.rust-lang.org/book/ch03-02-data-types.html#the-tuple-type -Now you have another tool in your toolbox!""" +现在,你的工具箱里又多了一个工具!""" # STRUCTS