# What is the status of language support for converting enums to/from their repr type?

**URL:** <https://internals.rust-lang.org/t/what-is-the-status-of-language-support-for-converting-enums-to-from-their-repr-type/22966>\
**Category:** language design\
**Created:** [May 21, 2025, 7:15pm UTC](https://internals.rust-lang.org/t/what-is-the-status-of-language-support-for-converting-enums-to-from-their-repr-type/22966 "2025-05-21T19:15:01Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![DragonDev1906](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@DragonDev1906](https://internals.rust-lang.org/u/DragonDev1906)\
**Post date:** [May 26, 2025, 7:57am UTC](https://internals.rust-lang.org/t/what-is-the-status-of-language-support-for-converting-enums-to-from-their-repr-type/22966/11 "2025-05-26T07:57:34Z")

</div>

> [@timClicks](#):
>
> I personally would push for extending `TryFrom` as far as possible. Once all avenues are exhausted, then we could introduce a new trait, e.g.`TryFromRepr`. Rust already has enough ways to convert between types.

> [@scovich](#):
>
> Maybe I had misunderstood, but I thought the intent of `#[derive(TryFromRepr)]` would be to request an `impl TryFrom<ReprType> for EnumType`, rather than actually introducing a new trait with that name?

Correct, initially I had `#[derive(TryFrom)]`, but it felt confusing as to what it's supposed to implement `TryFrom` for. I did not intend to suggest adding a new Trait.

Another (more flexible) option could be the following:

```rust
#[derive(TryFrom(u8, usize), Into(u8)]
#[repr(u8)]
enum MyEnum {...}

```

The more I think about it, the more I like it, as it could also be done for other traits, too. And it clearly shows what is derived. Though it does make the derive list longer.

> [@scovich](#):
>
> Would `TryFromRepr` also imply `IntoRepr`?

This I'm not sure about. You usually want both directions but in derive we usually/always have the trait names, as you said in a later comment, which makes it even more confusing what `#[derive(TryFrom)]` implements. That's why I choose a different name for it (even though it just implements `TryFrom`. In the back of my mind was also the idea of aliases/groups of traits that are derived (to reduce the need for large derive lists for newtype wrappers): [Pre-RFC: `#[derive(From)]` for newtypes - #17 by DragonDev1906](https://internals.rust-lang.org/t/pre-rfc-derive-from-for-newtypes/22567/17)

---

_[View the full topic](https://internals.rust-lang.org/t/what-is-the-status-of-language-support-for-converting-enums-to-from-their-repr-type/22966)._
