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
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)

@ -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!");// 译:"晚上好"
}
}

@ -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() {

@ -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.");// 译:"嗯,我把这样的数组当早餐吃。"
}
}

@ -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

@ -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);
}

@ -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!")// 译:这不是元组中的第二个数字!
}

@ -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

Loading…
Cancel
Save