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

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:

#[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.

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

1 Like