Open
Description
- Tuple destructuring (implemented in feature: Destructure Tuple Assist #9855)
- RecordStruct destructuring
- TupleStruct destructuring
- Improve the implementation Destructure assist #8673 (comment)
It would be nice to have an assist for destructuring a binding into its "subbindings" as in, when you have a name to a tuple value have it destructure into names for each componenet of the tuple, same for structure fields etc. See IntelliJ's implementation here https://github.com/intellij-rust/intellij-rust/blob/master/src/main/kotlin/org/rust/ide/intentions/DestructureIntention.kt
Some examples for how it should work:
let foo$0 = (1, 2, 3);
let bar = foo.0;
let _ = foo.into();
becomes
let (_0, _1, _2) = (1, 2, 3);
let bar = _0;
let _ = (_0, _1, _2).into();
Similarly this should work for TupleStructs and RecordStructs:
struct Foo { bar: i32 }
let foo$0 = Foo { bar: 1 };
let bar = foo.bar;
let _ = foo.into();
becomes
struct Foo { bar: i32 }
let Foo { bar } = Foo { bar: 1 };
let bar = bar;
let _ = (Foo { bar }).into();
This should also respect private fields as well as #[non_exhaustive]
, putting ..
in that case for the fields that aren't exposed.