|
|
@ -87,37 +87,35 @@ name = "functions2"
|
|
|
|
path = "exercises/functions/functions2.rs"
|
|
|
|
path = "exercises/functions/functions2.rs"
|
|
|
|
mode = "compile"
|
|
|
|
mode = "compile"
|
|
|
|
hint = """
|
|
|
|
hint = """
|
|
|
|
Rust 要求函数签名有类型标注,但是 `call_me` 函数缺少 `num` 的类型注明。"""
|
|
|
|
Rust 要求函数签名(signature)有类型标注,但是 `call_me` 函数缺少 `num` 的类型标注。"""
|
|
|
|
|
|
|
|
|
|
|
|
[[exercises]]
|
|
|
|
[[exercises]]
|
|
|
|
name = "functions3"
|
|
|
|
name = "functions3"
|
|
|
|
path = "exercises/functions/functions3.rs"
|
|
|
|
path = "exercises/functions/functions3.rs"
|
|
|
|
mode = "compile"
|
|
|
|
mode = "compile"
|
|
|
|
hint = """
|
|
|
|
hint = """
|
|
|
|
This time, the function *declaration* is okay, but there's something wrong
|
|
|
|
此时, 函数 *声明(declaration)* 是没问题的,但函数调用出了问题"""
|
|
|
|
with the place where we're calling the function."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[exercises]]
|
|
|
|
[[exercises]]
|
|
|
|
name = "functions4"
|
|
|
|
name = "functions4"
|
|
|
|
path = "exercises/functions/functions4.rs"
|
|
|
|
path = "exercises/functions/functions4.rs"
|
|
|
|
mode = "compile"
|
|
|
|
mode = "compile"
|
|
|
|
hint = """
|
|
|
|
hint = """
|
|
|
|
The error message points to line 14 and says it expects a type after the
|
|
|
|
错误信息指向第 15 行,说希望在`->`之后有一个类型。
|
|
|
|
`->`. This is where the function's return type should be-- take a look at
|
|
|
|
那个地方标注了函数的返回类型——看看 `is_even` 函数的示例吧"""
|
|
|
|
the `is_even` function for an example!"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[[exercises]]
|
|
|
|
[[exercises]]
|
|
|
|
name = "functions5"
|
|
|
|
name = "functions5"
|
|
|
|
path = "exercises/functions/functions5.rs"
|
|
|
|
path = "exercises/functions/functions5.rs"
|
|
|
|
mode = "compile"
|
|
|
|
mode = "compile"
|
|
|
|
hint = """
|
|
|
|
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
|
|
|
|
发生的原因是 Rust 区分了表达式和语句:表达式根据其运算数(operand)返回一个值,
|
|
|
|
a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
|
|
|
|
而语句仅返回一个 `()` 类型,其行为好比 C/C++ 中的 `void` 。
|
|
|
|
We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
|
|
|
|
我们希望 `square` 函数返回一个 `i32` 类型的值,但现在它返回的是 `()` 类型...
|
|
|
|
They are not the same. There are two solutions:
|
|
|
|
它们显然是不一样的。对此有两种解决方案。
|
|
|
|
1. Add a `return` ahead of `num * num;`
|
|
|
|
1. 在 `num * num;` 前面加上 `return` 关键字
|
|
|
|
2. remove `;`, make it to be `num * num`"""
|
|
|
|
2. 移除 `;`,让它变成 `num * num`"""
|
|
|
|
|
|
|
|
|
|
|
|
# IF
|
|
|
|
# IF
|
|
|
|
|
|
|
|
|
|
|
|