aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-26 15:38:03 +0000
committerGitHub <[email protected]>2020-03-26 15:38:03 +0000
commit20c110e57f24aa54154942ee40921e9129fbc595 (patch)
treea235a1338f590a243c3fd1302ac2e32ec4d24f05 /docs
parent0a8e65cf850ec3642fa51a3b71a4a7564c46a89b (diff)
parentd9df0f43ac669a68dc76466a2f2c21885b5af2dd (diff)
Merge #3732
3732: Assist: replace unwrap with match r=matklad a=unrealhoang attempt on #3669 Co-authored-by: Unreal Hoang <[email protected]>
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.