rust-lang / rust-lang/rust-analyzer
New assist: Generate `From` implementations from `from()` or `into()` calls.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Given a B::from(a) or a.into() call which is currently erroring with an unsatisfied From<A> or Into<B> bound, this assist would generate the skeleton of the appropriate impl:
impl From<A> for B {
fn from(value: A) -> Self {
todo!()
}
}
A further elaboration might be to sketch the body:
- If
Ais an enum, automatically insert amatch value { <arms> }. - If
Ais a struct with public fields, automatically insertlet A { <fields> } = value;. - If
Bis a struct with public fields, automatically insertSelf { <fields> }.
This assist would greatly speed up the process of writing type conversion boilerplate, and would make writing Froms at least as easy as writing plain functions with the “Generate function” assist.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by examining the existing “Generate function” assist referenced in the issue and how rust-analyzer assists are structured. Implement generation of the From<A> for B skeleton for failing from() or into() calls, then consider whether the enum and struct body elaborations belong in the same scope; done means the assist produces the requested implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100