mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-23 04:29:41 +00:00
fix errors in enum.md
This commit is contained in:
@ -19,7 +19,7 @@
|
||||
- [枚举](compound-types/enum.md)
|
||||
- [流程控制](flow-control.md)
|
||||
- [模式匹配 todo](pattern-match/intro.md)
|
||||
- [match 和 if let](pattern-match/match-iflet.md)
|
||||
- [match, matches! 和 if let](pattern-match/match-iflet.md)
|
||||
- [解构 Option](pattern-match/option.md)
|
||||
- [模式](pattern-match/patterns.md)
|
||||
- [方法 Method todo](method.md)
|
||||
|
@ -48,7 +48,7 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
🌟🌟🌟 枚举成员中的值可以使用模式匹配来获取
|
||||
🌟🌟 枚举成员中的值可以使用模式匹配来获取
|
||||
```rust,editable
|
||||
|
||||
// 仅填空,不要修改其它代码!
|
||||
@ -63,14 +63,14 @@ fn main() {
|
||||
let msg = Message::Move{x: 1, y: 1};
|
||||
|
||||
if let Message::Move{__} = msg {
|
||||
assert_eq!(x, y);
|
||||
assert_eq!(a, b);
|
||||
} else {
|
||||
panic!("不要让这行代码运行!");
|
||||
}
|
||||
|
||||
panic!("不要让这行代码运行!");
|
||||
}
|
||||
```
|
||||
|
||||
🌟🌟🌟 使用枚举对类型进行同一化
|
||||
🌟🌟 使用枚举对类型进行同一化
|
||||
|
||||
```rust,editable
|
||||
|
||||
@ -102,7 +102,7 @@ fn show_message(msg: Message) {
|
||||
🌟🌟 Rust 中没有 `null`,我们通过 `Option<T>` 枚举来处理值为空的情况
|
||||
```rust,editable
|
||||
|
||||
// 仅填空,不要修改其它代码!
|
||||
// 填空让 `println` 输出,同时添加一些代码不要让最后一行的 `panic` 执行到
|
||||
fn main() {
|
||||
let five = Some(5);
|
||||
let six = plus_one(five);
|
||||
@ -110,8 +110,8 @@ fn main() {
|
||||
|
||||
if let __ = six {
|
||||
println!("{}", n)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
panic!("不要让这行代码运行!");
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
# Iterator
|
||||
|
||||
https://doc.rust-lang.org/stable/rust-by-example/flow_control/for.html#for-and-iterators
|
Reference in New Issue
Block a user