Merge pull request #129 from mg-chao/20220105_translate_primitive_types

[rust-exercise] 翻译 primitive_types 内的所有内容
pull/135/head
Sunface 3 years ago committed by GitHub
commit 23120a005a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,9 +1,8 @@
# Primitive Types # 基本类型(Primitive Types
Rust has a couple of basic types that are directly implemented into the Rust 有几个直接在编译器中实现基本类型。在本节中,我们来看看最重要的几个。
compiler. In this section, we'll go through the most important ones.
## Further information ## 更多信息
- [Data Types](https://doc.rust-lang.org/stable/book/ch03-02-data-types.html) - [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) - [The Slice Type](https://doc.rust-lang.org/stable/book/ch04-03-slices.html)

@ -1,6 +1,6 @@
// primitive_types1.rs // 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 // I AM NOT DONE
@ -9,11 +9,11 @@ fn main() {
let is_morning = true; let is_morning = true;
if is_morning { 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 { if is_evening {
println!("Good evening!"); println!("Good evening!");// 译:"晚上好"
} }
} }

@ -1,6 +1,6 @@
// primitive_types2.rs // 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 // I AM NOT DONE
@ -9,16 +9,16 @@ fn main() {
let my_first_initial = 'C'; let my_first_initial = 'C';
if my_first_initial.is_alphabetic() { if my_first_initial.is_alphabetic() {
println!("Alphabetical!"); println!("Alphabetical!");// 译:"字母!"
} else if my_first_initial.is_numeric() { } else if my_first_initial.is_numeric() {
println!("Numerical!"); println!("Numerical!");// 译:"数字!"
} else { } else {
println!("Neither alphabetic nor numeric!"); println!("Neither alphabetic nor numeric!");// 译:"既不是字母也不是数字!"
} }
let // Finish this line like the example! What's your favorite character? let // 像上面的示例一样完成这行代码!你最喜欢的角色是什么?
// Try a letter, try a number, try a special character, try a character // 试试一个字母,或者一个数字,也可以一个特殊字符,又或者一个不属于
// from a different language than your own, try an emoji! // 你母语的字符,一个表情符号看起来也不错。
if your_character.is_alphabetic() { if your_character.is_alphabetic() {
println!("Alphabetical!"); println!("Alphabetical!");
} else if your_character.is_numeric() { } else if your_character.is_numeric() {

@ -1,6 +1,6 @@
// primitive_types3.rs // primitive_types3.rs
// Create an array with at least 100 elements in it where the ??? is. // 在 ??? 处创建一个不少于 100 个元素的数组。
// Execute `rustlings hint primitive_types3` for hints! // 执行 `rustex hint primitive_types3` 获取提示!
// I AM NOT DONE // I AM NOT DONE
@ -8,8 +8,8 @@ fn main() {
let a = ??? let a = ???
if a.len() >= 100 { if a.len() >= 100 {
println!("Wow, that's a big array!"); println!("Wow, that's a big array!");// 译:"哇!那数组可真大!"
} else { } else {
println!("Meh, I eat arrays like that for breakfast."); println!("Meh, I eat arrays like that for breakfast.");// 译:"嗯,我把这样的数组当早餐吃。"
} }
} }

@ -1,6 +1,6 @@
// primitive_types4.rs // primitive_types4.rs
// Get a slice out of Array a where the ??? is so that the test passes. // 在 ??? 处获取数组 a 的一个切片slice以通过测试。
// Execute `rustlings hint primitive_types4` for hints!! // 执行 `rustex hint primitive_types4` 获取提示!!
// I AM NOT DONE // I AM NOT DONE

@ -1,12 +1,12 @@
// primitive_types5.rs // primitive_types5.rs
// Destructure the `cat` tuple so that the println will work. // 对 `cat` 元组进行解构Destructure使 println 能够运行。
// Execute `rustlings hint primitive_types5` for hints! // 执行 `rustex hint primitive_types5` 获取提示!
// I AM NOT DONE // I AM NOT DONE
fn main() { fn main() {
let cat = ("Furry McFurson", 3.5); let cat = ("Furry McFurson", 3.5);
let /* your pattern here */ = cat; let /* your pattern here */ = cat;// 译:模式写在这
println!("{} is {} years old.", name, age); println!("{} is {} years old.", name, age);
} }

@ -1,16 +1,16 @@
// primitive_types6.rs // primitive_types6.rs
// Use a tuple index to access the second element of `numbers`. // 使用元组索引tuple index来访问 `numbers` 的第二个元素。
// You can put the expression for the second element where ??? is so that the test passes. // 你可以把第二个元素的表达式放在 ??? 处,这样测试就会通过。
// Execute `rustlings hint primitive_types6` for hints! // 执行 `rustex hint primitive_types6` 获取提示!
// I AM NOT DONE // I AM NOT DONE
#[test] #[test]
fn indexing_tuple() { fn indexing_tuple() {
let numbers = (1, 2, 3); let numbers = (1, 2, 3);
// Replace below ??? with the tuple indexing syntax. // 用元组索引的语法替换下面的 ???
let second = ???; let second = ???;
assert_eq!(2, second, assert_eq!(2, second,
"This is not the 2nd number in the tuple!") "This is not the 2nd number in the tuple!")// 译:这不是元组中的第二个数字!
} }

@ -212,40 +212,37 @@ https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#mutable-ref
name = "primitive_types1" name = "primitive_types1"
path = "exercises/primitive_types/primitive_types1.rs" path = "exercises/primitive_types/primitive_types1.rs"
mode = "compile" mode = "compile"
hint = "No hints this time ;)" hint = "这次没有提示 ;)"
[[exercises]] [[exercises]]
name = "primitive_types2" name = "primitive_types2"
path = "exercises/primitive_types/primitive_types2.rs" path = "exercises/primitive_types/primitive_types2.rs"
mode = "compile" mode = "compile"
hint = "No hints this time ;)" hint = "这次没有提示 ;)"
[[exercises]] [[exercises]]
name = "primitive_types3" name = "primitive_types3"
path = "exercises/primitive_types/primitive_types3.rs" path = "exercises/primitive_types/primitive_types3.rs"
mode = "compile" mode = "compile"
hint = """ hint = """
There's a shorthand to initialize Arrays with a certain size that does not 便 100
require you to type in 100 items (but you certainly can if you want!).
For example, you can do:
let array = ["Are we there yet?"; 10]; let array = ["Are we there yet?"; 10];
Bonus: what are some other things you could have that would return true : 西 `a.len()>=100` true """
for `a.len() >= 100`?"""
[[exercises]] [[exercises]]
name = "primitive_types4" name = "primitive_types4"
path = "exercises/primitive_types/primitive_types4.rs" path = "exercises/primitive_types/primitive_types4.rs"
mode = "test" mode = "test"
hint = """ hint = """
Take a look at the Understanding Ownership -> Slices -> Other Slices section of the book: Understanding Ownership -> Slices -> Other Slices
https://doc.rust-lang.org/book/ch04-03-slices.html 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.
If you're curious why the first argument of `assert_eq!` does not `assert_eq!`
have an ampersand for a reference since the second argument is a 使 & Deref
reference, take a look at the Deref coercions section of the book:
https://doc.rust-lang.org/book/ch15-02-deref.html""" https://doc.rust-lang.org/book/ch15-02-deref.html"""
[[exercises]] [[exercises]]
@ -253,22 +250,20 @@ name = "primitive_types5"
path = "exercises/primitive_types/primitive_types5.rs" path = "exercises/primitive_types/primitive_types5.rs"
mode = "compile" mode = "compile"
hint = """ 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 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 `name` `age` """
of the tuple. You can do it!!"""
[[exercises]] [[exercises]]
name = "primitive_types6" name = "primitive_types6"
path = "exercises/primitive_types/primitive_types6.rs" path = "exercises/primitive_types/primitive_types6.rs"
mode = "test" mode = "test"
hint = """ hint = """
While you could use a destructuring `let` for the tuple here, try 使 `let`
indexing into it instead, as explained in the last example of the Data Types -> The Tuple Type
Data Types -> The Tuple Type section of the book:
https://doc.rust-lang.org/book/ch03-02-data-types.html#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 # STRUCTS

Loading…
Cancel
Save