mirror of
https://github.com/sunface/rust-by-practice.git
synced 2025-06-27 06:29:42 +00:00
fix errors in enum.md
This commit is contained in:
@ -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!("不要让这行代码运行!");
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user