From e00febf87650fef10353617695d9dde0a582a6c9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 2 Jan 2022 11:12:07 +0800 Subject: [PATCH] update --- exercise/exercises/functions/functions2.rs | 2 +- exercise/exercises/functions/functions3.rs | 3 ++- exercise/exercises/functions/functions4.rs | 9 ++++---- exercise/exercises/functions/functions5.rs | 5 +++-- exercise/info.toml | 24 ++++++++++------------ 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/exercise/exercises/functions/functions2.rs b/exercise/exercises/functions/functions2.rs index 915ebec1..ff5b907a 100644 --- a/exercise/exercises/functions/functions2.rs +++ b/exercise/exercises/functions/functions2.rs @@ -10,6 +10,6 @@ fn main() { fn call_me(num:) { for i in 0..num { - println!("Ring! Call number {}", i + 1); + println!("Ring! Call number {}", i + 1);// 译:"叮!呼叫号码 {}" } } diff --git a/exercise/exercises/functions/functions3.rs b/exercise/exercises/functions/functions3.rs index ed5f839f..7ccff554 100644 --- a/exercise/exercises/functions/functions3.rs +++ b/exercise/exercises/functions/functions3.rs @@ -1,8 +1,9 @@ // functions3.rs -// Make me compile! Execute `rustlings hint functions3` for hints :) +// 让我能够编译!执行 `rustex hint functions3` 获取提示 :) // I AM NOT DONE +/// 翻译: [mg-chao](https://github.com/mg-chao) fn main() { call_me(); } diff --git a/exercise/exercises/functions/functions4.rs b/exercise/exercises/functions/functions4.rs index 58637e4c..a524ba96 100644 --- a/exercise/exercises/functions/functions4.rs +++ b/exercise/exercises/functions/functions4.rs @@ -1,14 +1,15 @@ // functions4.rs -// Make me compile! Execute `rustlings hint functions4` for hints :) +// 让我能够编译!执行 `rustex hint functions4` 获取提示 :) -// This store is having a sale where if the price is an even number, you get -// 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. +// 商店正在进行促销,如果价格是偶数,可以优惠 10 Rustbucks,如果是奇数,则优惠 3 Rustbucks。 +// 译:Rustbucks 可能想表达 Rust元 的意思,好比 美元 。 // I AM NOT DONE +/// 翻译: [mg-chao](https://github.com/mg-chao) fn main() { let original_price = 51; - println!("Your sale price is {}", sale_price(original_price)); + println!("Your sale price is {}", sale_price(original_price));// 译:"你需支付 {}" } fn sale_price(price: i32) -> { diff --git a/exercise/exercises/functions/functions5.rs b/exercise/exercises/functions/functions5.rs index d22aa6c8..fe5d8641 100644 --- a/exercise/exercises/functions/functions5.rs +++ b/exercise/exercises/functions/functions5.rs @@ -1,11 +1,12 @@ // functions5.rs -// Make me compile! Execute `rustlings hint functions5` for hints :) +// 让我能够编译!执行 `rustex hint functions5` 获取提示 :) // I AM NOT DONE +/// 翻译: [mg-chao](https://github.com/mg-chao) fn main() { let answer = square(3); - println!("The answer is {}", answer); + println!("The answer is {}", answer);// 译:"答案是 {}" } fn square(num: i32) -> i32 { diff --git a/exercise/info.toml b/exercise/info.toml index dca534de..ae0dd523 100644 --- a/exercise/info.toml +++ b/exercise/info.toml @@ -87,37 +87,35 @@ name = "functions2" path = "exercises/functions/functions2.rs" mode = "compile" hint = """ - Rust 要求函数签名有类型标注,但是 `call_me` 函数缺少 `num` 的类型注明。""" + Rust 要求函数签名(signature)有类型标注,但是 `call_me` 函数缺少 `num` 的类型标注。""" [[exercises]] name = "functions3" path = "exercises/functions/functions3.rs" mode = "compile" hint = """ -This time, the function *declaration* is okay, but there's something wrong -with the place where we're calling the function.""" +此时, 函数 *声明(declaration)* 是没问题的,但函数调用出了问题""" [[exercises]] name = "functions4" path = "exercises/functions/functions4.rs" mode = "compile" hint = """ -The error message points to line 14 and says it expects a type after the -`->`. This is where the function's return type should be-- take a look at -the `is_even` function for an example!""" +错误信息指向第 15 行,说希望在`->`之后有一个类型。 +那个地方标注了函数的返回类型——看看 `is_even` 函数的示例吧""" [[exercises]] name = "functions5" path = "exercises/functions/functions5.rs" mode = "compile" hint = """ -This is a really common error that can be fixed by removing one character. -It happens because Rust distinguishes between expressions and statements: expressions return -a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language. -We want to return a value of `i32` type from the `square` function, but it is returning a `()` type... -They are not the same. There are two solutions: -1. Add a `return` ahead of `num * num;` -2. remove `;`, make it to be `num * num`""" +这是一个非常常见的错误,可以通过删除一个字符来解决。 +发生的原因是 Rust 区分了表达式和语句:表达式根据其运算数(operand)返回一个值, +而语句仅返回一个 `()` 类型,其行为好比 C/C++ 中的 `void` 。 +我们希望 `square` 函数返回一个 `i32` 类型的值,但现在它返回的是 `()` 类型... +它们显然是不一样的。对此有两种解决方案。 +1. 在 `num * num;` 前面加上 `return` 关键字 +2. 移除 `;`,让它变成 `num * num`""" # IF