diff options
author | Unreal Hoang <[email protected]> | 2020-03-26 09:16:10 +0000 |
---|---|---|
committer | Unreal Hoang <[email protected]> | 2020-03-26 15:08:12 +0000 |
commit | d9df0f43ac669a68dc76466a2f2c21885b5af2dd (patch) | |
tree | c20d4c2a698b33c83014664754379b182b659dc9 /docs/user | |
parent | 785eb32f49653fbc5789396af4fa6ad61f89fb38 (diff) |
Assist: replace unwrap with match
Diffstat (limited to 'docs/user')
-rw-r--r-- | docs/user/assists.md | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md index f3ce6b0e0..b2568a954 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -597,6 +597,29 @@ use std::collections::HashMap; | |||
597 | fn process(map: HashMap<String, String>) {} | 597 | fn process(map: HashMap<String, String>) {} |
598 | ``` | 598 | ``` |
599 | 599 | ||
600 | ## `replace_unwrap_with_match` | ||
601 | |||
602 | Replaces `unwrap` a `match` expression. Works for Result and Option. | ||
603 | |||
604 | ```rust | ||
605 | // BEFORE | ||
606 | enum Result<T, E> { Ok(T), Err(E) } | ||
607 | fn main() { | ||
608 | let x: Result<i32, i32> = Result::Ok(92); | ||
609 | let y = x.┃unwrap(); | ||
610 | } | ||
611 | |||
612 | // AFTER | ||
613 | enum Result<T, E> { Ok(T), Err(E) } | ||
614 | fn main() { | ||
615 | let x: Result<i32, i32> = Result::Ok(92); | ||
616 | let y = match x { | ||
617 | Ok(a) => a, | ||
618 | _ => unreachable!(), | ||
619 | }; | ||
620 | } | ||
621 | ``` | ||
622 | |||
600 | ## `split_import` | 623 | ## `split_import` |
601 | 624 | ||
602 | Wraps the tail of import into braces. | 625 | Wraps the tail of import into braces. |