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