diff options
Diffstat (limited to 'docs/user/assists.md')
-rw-r--r-- | docs/user/assists.md | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md index cb4b0b9fb..eeb486832 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -1,5 +1,142 @@ | |||
1 | # Assists | 1 | # Assists |
2 | 2 | ||
3 | ## `add_derive` | ||
4 | |||
5 | Adds a new `#[derive()]` clause to a struct or enum. | ||
6 | |||
7 | ```rust | ||
8 | // BEFORE | ||
9 | struct Point { | ||
10 | x: u32, | ||
11 | y: u32,<|> | ||
12 | } | ||
13 | |||
14 | // AFTER | ||
15 | #[derive()] | ||
16 | struct Point { | ||
17 | x: u32, | ||
18 | y: u32, | ||
19 | } | ||
20 | ``` | ||
21 | |||
22 | ## `add_explicit_type` | ||
23 | |||
24 | Specify type for a let binding | ||
25 | |||
26 | ```rust | ||
27 | // BEFORE | ||
28 | fn main() { | ||
29 | let x<|> = 92; | ||
30 | } | ||
31 | |||
32 | // AFTER | ||
33 | fn main() { | ||
34 | let x: i32 = 92; | ||
35 | } | ||
36 | ``` | ||
37 | |||
38 | ## `add_impl` | ||
39 | |||
40 | Adds a new inherent impl for a type | ||
41 | |||
42 | ```rust | ||
43 | // BEFORE | ||
44 | struct Ctx<T: Clone> { | ||
45 | data: T,<|> | ||
46 | } | ||
47 | |||
48 | // AFTER | ||
49 | struct Ctx<T: Clone> { | ||
50 | data: T, | ||
51 | } | ||
52 | |||
53 | impl<T: Clone> Ctx<T> { | ||
54 | |||
55 | } | ||
56 | ``` | ||
57 | |||
58 | ## `add_impl_default_members` | ||
59 | |||
60 | Adds scaffold for overriding default impl members | ||
61 | |||
62 | ```rust | ||
63 | // BEFORE | ||
64 | trait T { | ||
65 | Type X; | ||
66 | fn foo(&self); | ||
67 | fn bar(&self) {} | ||
68 | } | ||
69 | |||
70 | impl T for () { | ||
71 | Type X = (); | ||
72 | fn foo(&self) {}<|> | ||
73 | |||
74 | } | ||
75 | |||
76 | // AFTER | ||
77 | trait T { | ||
78 | Type X; | ||
79 | fn foo(&self); | ||
80 | fn bar(&self) {} | ||
81 | } | ||
82 | |||
83 | impl T for () { | ||
84 | Type X = (); | ||
85 | fn foo(&self) {} | ||
86 | fn bar(&self) {} | ||
87 | |||
88 | } | ||
89 | ``` | ||
90 | |||
91 | ## `add_impl_missing_members` | ||
92 | |||
93 | Adds scaffold for required impl members | ||
94 | |||
95 | ```rust | ||
96 | // BEFORE | ||
97 | trait T { | ||
98 | Type X; | ||
99 | fn foo(&self); | ||
100 | fn bar(&self) {} | ||
101 | } | ||
102 | |||
103 | impl T for () {<|> | ||
104 | |||
105 | } | ||
106 | |||
107 | // AFTER | ||
108 | trait T { | ||
109 | Type X; | ||
110 | fn foo(&self); | ||
111 | fn bar(&self) {} | ||
112 | } | ||
113 | |||
114 | impl T for () { | ||
115 | fn foo(&self) { unimplemented!() } | ||
116 | |||
117 | } | ||
118 | ``` | ||
119 | |||
120 | ## `apply_demorgan` | ||
121 | |||
122 | Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). | ||
123 | This transforms expressions of the form `!l || !r` into `!(l && r)`. | ||
124 | This also works with `&&`. This assist can only be applied with the cursor | ||
125 | on either `||` or `&&`, with both operands being a negation of some kind. | ||
126 | This means something of the form `!x` or `x != y`. | ||
127 | |||
128 | ```rust | ||
129 | // BEFORE | ||
130 | fn main() { | ||
131 | if x != 4 ||<|> !y {} | ||
132 | } | ||
133 | |||
134 | // AFTER | ||
135 | fn main() { | ||
136 | if !(x == 4 && y) {} | ||
137 | } | ||
138 | ``` | ||
139 | |||
3 | ## `convert_to_guarded_return` | 140 | ## `convert_to_guarded_return` |
4 | 141 | ||
5 | Replace a large conditional with a guarded return. | 142 | Replace a large conditional with a guarded return. |