From b5216178fd450dc069665cfa04d33da71e4999dc Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 1 Jan 2022 12:43:55 +0800 Subject: [PATCH] update: translate variables --- exercise/exercises/variables/README.md | 10 ++-- exercise/exercises/variables/variables1.rs | 2 +- exercise/exercises/variables/variables2.rs | 7 +-- exercise/exercises/variables/variables3.rs | 6 +-- exercise/exercises/variables/variables4.rs | 2 +- exercise/exercises/variables/variables5.rs | 6 +-- exercise/exercises/variables/variables6.rs | 2 +- exercise/info.toml | 53 ++++++++++------------ 8 files changed, 42 insertions(+), 46 deletions(-) diff --git a/exercise/exercises/variables/README.md b/exercise/exercises/variables/README.md index 11a7a78a..9a47a74d 100644 --- a/exercise/exercises/variables/README.md +++ b/exercise/exercises/variables/README.md @@ -1,9 +1,9 @@ -# Variables +# 变量(Variables) -In Rust, variables are immutable by default. -When a variable is immutable, once a value is bound to a name, you can’t change that value. -You can make them mutable by adding mut in front of the variable name. +在 Rust,变量默认是不可变的. +不可变意味着当一个值被绑定到某个名字上,你就不能再对这个值做出更改。 +当然,你可以通过在变量名前添加 mut 来使它们变得可变。 -## Further information +## 更多信息 - [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html) diff --git a/exercise/exercises/variables/variables1.rs b/exercise/exercises/variables/variables1.rs index fb391d22..5c352d04 100644 --- a/exercise/exercises/variables/variables1.rs +++ b/exercise/exercises/variables/variables1.rs @@ -12,5 +12,5 @@ /// 加油 💪 fn main() { x = 5; - println!("x has the value {}", x); + println!("x has the value {}", x);// 译:x 的值是 } diff --git a/exercise/exercises/variables/variables2.rs b/exercise/exercises/variables/variables2.rs index 7774a8fb..c08e12ec 100644 --- a/exercise/exercises/variables/variables2.rs +++ b/exercise/exercises/variables/variables2.rs @@ -1,13 +1,14 @@ // variables2.rs -// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) +// 让我能够编译!执行 `rustex hint variables2` 获取提示 :) // I AM NOT DONE +/// 翻译: [mg-chao](https://github.com/mg-chao) fn main() { let x; if x == 10 { - println!("Ten!"); + println!("Ten!");// 译:十! } else { - println!("Not ten!"); + println!("Not ten!");// 译:不是十! } } diff --git a/exercise/exercises/variables/variables3.rs b/exercise/exercises/variables/variables3.rs index 30ec48ff..cf69ebd2 100644 --- a/exercise/exercises/variables/variables3.rs +++ b/exercise/exercises/variables/variables3.rs @@ -1,11 +1,11 @@ // variables3.rs -// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) +// 让我能够编译!执行 `rustex hint variables3` 获取提示 :) // I AM NOT DONE fn main() { let x = 3; - println!("Number {}", x); - x = 5; // don't change this line + println!("Number {}", x);// 译:"数字 {}" + x = 5; // don't change this line(译:不要更改这一行) println!("Number {}", x); } diff --git a/exercise/exercises/variables/variables4.rs b/exercise/exercises/variables/variables4.rs index 77f1e9ab..80339890 100644 --- a/exercise/exercises/variables/variables4.rs +++ b/exercise/exercises/variables/variables4.rs @@ -1,5 +1,5 @@ // variables4.rs -// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) +// 让我能够编译!执行 `rustex hint variables4` 获取提示 :) // I AM NOT DONE diff --git a/exercise/exercises/variables/variables5.rs b/exercise/exercises/variables/variables5.rs index 175eebb3..09ecf810 100644 --- a/exercise/exercises/variables/variables5.rs +++ b/exercise/exercises/variables/variables5.rs @@ -1,11 +1,11 @@ // variables5.rs -// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) +// 让我能够编译!执行 `rustex hint variables5` 获取提示 :) // I AM NOT DONE fn main() { let number = "T-H-R-E-E"; // don't change this line - println!("Spell a Number : {}", number); + println!("Spell a Number : {}", number);// 译:"拼接的数字:{}" number = 3; - println!("Number plus two is : {}", number + 2); + println!("Number plus two is : {}", number + 2);// 译:"数字加上二是:{}" } diff --git a/exercise/exercises/variables/variables6.rs b/exercise/exercises/variables/variables6.rs index 98666914..2d83d656 100644 --- a/exercise/exercises/variables/variables6.rs +++ b/exercise/exercises/variables/variables6.rs @@ -1,5 +1,5 @@ // variables6.rs -// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) +// 让我能够编译!执行 `rustex hint variables6` 获取提示 :) // I AM NOT DONE diff --git a/exercise/info.toml b/exercise/info.toml index 38e271e8..22ce26b3 100644 --- a/exercise/info.toml +++ b/exercise/info.toml @@ -13,62 +13,57 @@ name = "variables2" path = "exercises/variables/variables2.rs" mode = "compile" hint = """ -The compiler message is saying that Rust cannot infer the type that the -variable binding `x` has with what is given here. -What happens if you annotate line 7 with a type annotation? -What if you give x a value? -What if you do both? -What type should x be, anyway? -What if x is the same type as 10? What if it's a different type?""" +编译器在说,Rust 无法根据给定内容推断出变量 `x` 的类型. +如果你对第 7 行注明类型,会发生什么? +如果你对 x 赋予一个值呢? +如果你同时做到了以上两点呢? + x 到底是什么类型? +如果 x 与 10 是同一类型,亦或者它是不同的类型呢?""" [[exercises]] name = "variables3" path = "exercises/variables/variables3.rs" mode = "compile" hint = """ -In Rust, variable bindings are immutable by default. But here we're trying -to reassign a different value to x! There's a keyword we can use to make -a variable binding mutable instead.""" +在 Rust,变量绑定默认是不可变的。但我们正试图重新分配 +一个不同的值给 x !我们可以使用一个关键字使变量可变。""" [[exercises]] name = "variables4" path = "exercises/variables/variables4.rs" mode = "compile" hint = """ -Oops! In this exercise, we have a variable binding that we've created on -line 7, and we're trying to use it on line 8, but we haven't given it a -value. We can't print out something that isn't there; try giving x a value! -This is an error that can cause bugs that's very easy to make in any -programming language -- thankfully the Rust compiler has caught this for us!""" +糟了!在这个练习中,我们在第 7 行创建了一个变量,然后试图在第 8 行 +使用它,但是它并没被赋值!我们无法打印出不存在的内容,所以尝试赋予 x 一个值! +这个错误造成的 Bug 在任何编程语言中都非常容易发生——感谢 Rust 编译器提醒了我们""" [[exercises]] name = "variables5" path = "exercises/variables/variables5.rs" mode = "compile" hint = """ -In variables3 we already learned how to make an immutable variable mutable -using a special keyword. Unfortunately this doesn't help us much in this exercise -because we want to assign a different typed value to an existing variable. Sometimes -you may also like to reuse existing variable names because you are just converting -values to different types like in this exercise. -Fortunately Rust has a powerful solution to this problem: 'Shadowing'! -You can read more about 'Shadowing' in the book's section 'Variables and Mutability': +在 variables3 中,我们已经学会了使用一个特殊的关键字使一个不可变的变量变得可变。 +可惜的是,在这个练习中,这个方法并不管用,因为我们想给一个现有的变量分配一个不 +同类型的值。有时,你会想重复使用现有的变量名称,因为你只是将数值转换为不同的类型,就像 +本练习中一样。幸运的是,Rust 有一个强大的技术可以解决这个问题:变量遮蔽(Shadowing)! +有关变量遮蔽的更多内容可通过这本书的 'Variables and Mutability'* 章节了解: https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#shadowing -Try to solve this exercise afterwards using this technique.""" +尝试使用此技术解决此练习。 + +译:Variables and Mutability:变量与可变性""" [[exercises]] name = "variables6" path = "exercises/variables/variables6.rs" mode = "compile" hint = """ -We know about variables and mutability, but there is another important type of -variable available; constants. -Constants are always immutable and they are declared with keyword 'const' rather -than keyword 'let'. -Constants types must also always be annotated. +我们已经了解了变量与可变性,但还有另一种重要的变量类型;常量(Constant)。 +常量永远不可改变的,它用关键字 'const' 而非关键字 'let' 声明,并且其类型也必须被注明。 -Read more about constants under 'Differences Between Variables and Constants' in the book's section 'Variables and Mutability': +更多关于常量的信息 'Differences Between Variables and Constants'* 在这本书的章节 'Variables and Mutability': https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html#differences-between-variables-and-constants + +译:Differences Between Variables and Constants:变量与常量的区别 """ # FUNCTIONS