rust-lang / rust-lang/rust-analyzer
TryFrom implementation for `repr` tagged enums assist
Open
@A4-Tacks is already working on this.
Since May 4, 2026.
A-assists
C-feature
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
If you have an enum like:
#[repr(u8)]
enum Data {
Ok = 0x00,
Error = 0x01,
}
I think it would be handy to have it generate a TryFrom implementation. The error type could be set to (), it's easy to replace if need be.
Something like:
impl TryFrom<u8> for Data {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0x00 => Ok(Self::Data),
0x01 => Ok(Self::Error),
_ => return Err(()),
}
}
}
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.
Assessment
This issue has not been assessed yet.