3 Cursor position or selection is signified by `┃` character.
8 Adds impl block for derived trait.
12 #[derive(Deb┃ug, Display)]
26 Adds a new `#[derive()]` clause to a struct or enum.
43 ## `add_explicit_type`
45 Specify type for a let binding.
61 Adds a stub function with a signature matching the function under the cursor.
66 fn baz() -> Baz { Baz }
74 fn baz() -> Baz { Baz }
79 fn bar(arg: &str, baz: Baz) {
87 Adds a hash to a raw string literal.
103 Adds a new inherent impl for a type.
107 struct Ctx<T: Clone> {
112 struct Ctx<T: Clone> {
116 impl<T: Clone> Ctx<T> {
121 ## `add_impl_default_members`
123 Adds scaffold for overriding default impl members.
154 ## `add_impl_missing_members`
156 Adds scaffold for required impl members.
166 impl Trait<u32> for () {┃
177 impl Trait<u32> for () {
178 fn foo(&self) -> u32 {
187 Adds a new inherent impl for a type.
191 struct Ctx<T: Clone> {
196 struct Ctx<T: Clone> {
200 impl<T: Clone> Ctx<T> {
201 fn new(data: T) -> Self { Self { data } }
208 Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
209 This transforms expressions of the form `!l || !r` into `!(l && r)`.
210 This also works with `&&`. This assist can only be applied with the cursor
211 on either `||` or `&&`, with both operands being a negation of some kind.
212 This means something of the form `!x` or `x != y`.
228 If the name is unresolved, provides all possible imports for it.
233 let map = HashMap┃::new();
237 use std::collections::HashMap;
240 let map = HashMap::new();
244 ## `change_return_type_to_result`
246 Change the function's return type to Result.
250 fn foo() -> i32┃ { 42i32 }
253 fn foo() -> Result<i32, > { Ok(42i32) }
256 ## `change_visibility`
258 Adds or changes existing visibility specifier.
265 pub(crate) fn frobnicate() {}
268 ## `convert_to_guarded_return`
270 Replace a large conditional with a guarded return.
293 Adds missing clauses to a `match` expression.
297 enum Action { Move { distance: u32 }, Stop }
299 fn handle(action: Action) {
306 enum Action { Move { distance: u32 }, Stop }
308 fn handle(action: Action) {
310 Action::Move { distance } => {}
318 Flips operands of a binary expression.
334 Flips two comma-separated items.
348 ## `flip_trait_bound`
350 Flips two trait bounds.
354 fn foo<T: Clone +┃ Copy>() { }
357 fn foo<T: Copy + Clone>() { }
360 ## `inline_local_variable`
362 Inlines local variable.
377 ## `introduce_variable`
379 Extracts subexpression into a variable.
389 let var_name = (1 + 2);
397 This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}`
398 This also works with `!=`. This assist can only be applied with the cursor
404 if┃ !y { A } else { B }
409 if y { B } else { A }
415 Adds `r#` to a plain string literal.
429 ## `make_usual_string`
431 Turns a raw string into a plain string.
436 r#"Hello,┃ "World!""#;
447 Merges two imports with a common prefix.
451 use std::┃fmt::Formatter;
455 use std::{fmt::Formatter, io};
458 ## `merge_match_arms`
460 Merges identical match arms.
464 enum Action { Move { distance: u32 }, Stop }
466 fn handle(action: Action) {
468 ┃Action::Move(..) => foo(),
469 Action::Stop => foo(),
474 enum Action { Move { distance: u32 }, Stop }
476 fn handle(action: Action) {
478 Action::Move(..) | Action::Stop => foo(),
483 ## `move_arm_cond_to_match_guard`
485 Moves if expression from match arm body into a guard.
489 enum Action { Move { distance: u32 }, Stop }
491 fn handle(action: Action) {
493 Action::Move { distance } => ┃if distance > 10 { foo() },
499 enum Action { Move { distance: u32 }, Stop }
501 fn handle(action: Action) {
503 Action::Move { distance } if distance > 10 => foo(),
509 ## `move_bounds_to_where_clause`
511 Moves inline type bounds to a where clause.
515 fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U {
520 fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
525 ## `move_guard_to_arm_body`
527 Moves match guard into match arm body.
531 enum Action { Move { distance: u32 }, Stop }
533 fn handle(action: Action) {
535 Action::Move { distance } ┃if distance > 10 => foo(),
541 enum Action { Move { distance: u32 }, Stop }
543 fn handle(action: Action) {
545 Action::Move { distance } => if distance > 10 { foo() },
553 Removes `dbg!()` macro call.
569 Removes a hash from a raw string literal.
585 Removes the `mut` keyword.
590 fn feed(&mut┃ self, amount: u32) {}
595 fn feed(&self, amount: u32) {}
601 Reorder the fields of record literals and record patterns in the same order as in
606 struct Foo {foo: i32, bar: i32};
607 const test: Foo = ┃Foo {bar: 0, foo: 1}
610 struct Foo {foo: i32, bar: i32};
611 const test: Foo = Foo {foo: 1, bar: 0}
614 ## `replace_if_let_with_match`
616 Replaces `if let` with an else branch with a `match` expression.
620 enum Action { Move { distance: u32 }, Stop }
622 fn handle(action: Action) {
623 ┃if let Action::Move { distance } = action {
631 enum Action { Move { distance: u32 }, Stop }
633 fn handle(action: Action) {
635 Action::Move { distance } => foo(distance),
641 ## `replace_let_with_if_let`
643 Replaces `let` with an `if-let`.
648 fn main(action: Action) {
652 fn compute() -> Option<i32> { None }
656 fn main(action: Action) {
657 if let Some(x) = compute() {
661 fn compute() -> Option<i32> { None }
664 ## `replace_qualified_name_with_use`
666 Adds a use statement for a given fully-qualified name.
670 fn process(map: std::collections::┃HashMap<String, String>) {}
673 use std::collections::HashMap;
675 fn process(map: HashMap<String, String>) {}
678 ## `replace_unwrap_with_match`
680 Replaces `unwrap` a `match` expression. Works for Result and Option.
684 enum Result<T, E> { Ok(T), Err(E) }
686 let x: Result<i32, i32> = Result::Ok(92);
691 enum Result<T, E> { Ok(T), Err(E) }
693 let x: Result<i32, i32> = Result::Ok(92);
703 Wraps the tail of import into braces.
707 use std::┃collections::HashMap;
710 use std::{collections::HashMap};
715 This assist removes if...else, for, while and loop control statements to just keep the body.