rust-lang / rust-lang/rust-analyzer
Convert enum to struct assist
Open
Nobody has claimed this yet.
A-assists
C-feature
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
This is useful for hiding enum variants from a public API.
e.g.
#[derive(Copy, Clone, Debug)]
pub enum Something {
Foo,
Bar(u32),
}
fn foo(s: &Something) -> u32 {
match s {
Something::Foo => 0,
Something::Bar(value) => value,
}
}
fn bar() -> Something {
Something::Foo
}
to
#[derive(Copy, Clone, Debug)]
#[repr(transparent)] // In case of transmute shenanigans
pub struct Something {
kind: SomethingKind,
}
// Duplicates basic derives (can't duplicate all because it may change semantics, e.g. serde)
#[derive(Copy, Clone, Debug)]
enum SomethingKind {
Foo,
Bar(u32),
}
fn foo(s: &Something) -> u32 {
match &s.kind {
Something::Foo => 0,
Something::Bar(value) => value,
}
}
fn bar() -> Something {
Something { kind: SomethingKind::Foo }
}
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
The issue names no source files, tests, or entry points. Use the enum-to-struct examples as the specification, then define which enum shapes and derives the assist supports and how completion will be verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100