From d9df0f43ac669a68dc76466a2f2c21885b5af2dd Mon Sep 17 00:00:00 2001 From: Unreal Hoang Date: Thu, 26 Mar 2020 18:16:10 +0900 Subject: Assist: replace unwrap with match --- docs/user/assists.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'docs') 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; fn process(map: HashMap) {} ``` +## `replace_unwrap_with_match` + +Replaces `unwrap` a `match` expression. Works for Result and Option. + +```rust +// BEFORE +enum Result { Ok(T), Err(E) } +fn main() { + let x: Result = Result::Ok(92); + let y = x.┃unwrap(); +} + +// AFTER +enum Result { Ok(T), Err(E) } +fn main() { + let x: Result = Result::Ok(92); + let y = match x { + Ok(a) => a, + _ => unreachable!(), + }; +} +``` + ## `split_import` Wraps the tail of import into braces. -- cgit v1.2.3