aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorUnreal Hoang <[email protected]>2020-03-26 09:16:10 +0000
committerUnreal Hoang <[email protected]>2020-03-26 15:08:12 +0000
commitd9df0f43ac669a68dc76466a2f2c21885b5af2dd (patch)
treec20d4c2a698b33c83014664754379b182b659dc9 /docs
parent785eb32f49653fbc5789396af4fa6ad61f89fb38 (diff)
Assist: replace unwrap with match
Diffstat (limited to 'docs')
-rw-r--r--docs/user/assists.md23
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;
597fn process(map: HashMap<String, String>) {} 597fn process(map: HashMap<String, String>) {}
598``` 598```
599 599
600## `replace_unwrap_with_match`
601
602Replaces `unwrap` a `match` expression. Works for Result and Option.
603
604```rust
605// BEFORE
606enum Result<T, E> { Ok(T), Err(E) }
607fn main() {
608 let x: Result<i32, i32> = Result::Ok(92);
609 let y = x.┃unwrap();
610}
611
612// AFTER
613enum Result<T, E> { Ok(T), Err(E) }
614fn 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
602Wraps the tail of import into braces. 625Wraps the tail of import into braces.