Merge pull request #120 from mg-chao/20220103_translate_if

[rust-exercise] 翻译 if 内的所有内容
pull/126/head
Sunface 3 years ago committed by GitHub
commit 1b6ae4c281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,7 +1,7 @@
# If # If
`if`, the most basic type of control flow, is what you'll learn here. 你将在这学习最基本的控制流control flow——`if`
## Further information ## 更多信息
- [Control Flow - if expressions](https://doc.rust-lang.org/book/ch03-05-control-flow.html#if-expressions) - [Control Flow - if expressions](https://doc.rust-lang.org/book/ch03-05-control-flow.html#if-expressions)

@ -3,14 +3,14 @@
// I AM NOT DONE // I AM NOT DONE
pub fn bigger(a: i32, b: i32) -> i32 { pub fn bigger(a: i32, b: i32) -> i32 {
// Complete this function to return the bigger number! // 完成这个返回更大数字的函数!
// Do not use: // 但不允许以下方式:
// - another function call // - 调用其它函数
// - additional variables // - 额外变量
// Execute `rustlings hint if1` for hints // 执行 `rustex hint if1` 获取提示
} }
// Don't mind this for now :) // 暂时不要在意它 :)
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

@ -1,8 +1,8 @@
// if2.rs // if2.rs
// Step 1: Make me compile! // 第一步:让我能够编译!
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // 第二步bar_for_fuzz 和 default_to_baz 可以通过测试!
// Execute the command `rustlings hint if2` if you want a hint :) // 执行 `rustex hint if2` 获取提示 :)
// I AM NOT DONE // I AM NOT DONE
@ -14,7 +14,7 @@ pub fn fizz_if_foo(fizzish: &str) -> &str {
} }
} }
// No test changes needed! // 测试不需要更改。
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

@ -119,23 +119,23 @@ name = "if1"
path = "exercises/if/if1.rs" path = "exercises/if/if1.rs"
mode = "test" mode = "test"
hint = """ hint = """
It's possible to do this in one line if you would like! !
Some similar examples from other languages: :
- In C(++) this would be: `a > b ? a : b` - C(++) : `a > b ? a : b`
- In Python this would be: `a if a > b else b` - Python : `a if a > b else b`
Remember in Rust that: Rust
- the `if` condition does not need to be surrounded by parentheses - `if`
- `if`/`else` conditionals are expressions - `if`/`else`
- Each condition is followed by a `{}` block.""" - `{}` """
[[exercises]] [[exercises]]
name = "if2" name = "if2"
path = "exercises/if/if2.rs" path = "exercises/if/if2.rs"
mode = "test" mode = "test"
hint = """ hint = """
For that first compiler error, it's important in Rust that each conditional Rust
block return the same type! To get the tests passing, you will need a couple conditional block
conditions checking different input values.""" """
# TEST 1 # TEST 1

Loading…
Cancel
Save