From 76e9a8f724ab19aaf4033f3f2f58311256752b7e Mon Sep 17 00:00:00 2001 From: zrll_ <46812903+zrll12@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:03:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/basic/match-pattern/pattern-match.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/basic/match-pattern/pattern-match.md b/src/basic/match-pattern/pattern-match.md index 94b3aef1..76da5b78 100644 --- a/src/basic/match-pattern/pattern-match.md +++ b/src/basic/match-pattern/pattern-match.md @@ -201,9 +201,8 @@ if let Some(x) = some_option_value { } // let-else -let Some(x) = some_option_value { - println!("{}", x); -} else { return; } +let Some(x) = some_option_value else { return; } +println!("{}", x); ``` 在上面的例子中,`if let`写法里的`x`只能在`if`分支内使用,而`let-else`写法里的`x`则可以在`let`之外使用。