update: translate variables

pull/110/head
unknown 3 years ago
parent 718c89ea91
commit b5216178fd

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

@ -12,5 +12,5 @@
/// 加油 💪
fn main() {
x = 5;
println!("x has the value {}", x);
println!("x has the value {}", x);// 译x 的值是
}

@ -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!");// 译:不是十!
}
}

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

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

@ -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);// 译:"数字加上二是:{}"
}

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

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

Loading…
Cancel
Save