Peternator7 / strum

A small rust library for adding custom derives to enums
https://crates.io/crates/strum
MIT License
1.81k stars 152 forks source link

feature request: AsRefStr using the discriminant as UTF-8 #247

Closed ericlagergren closed 1 year ago

ericlagergren commented 1 year ago

I have an enum like this:

#[repr(u32)]
enum Foo {
    ID = 0x44492323, // = ##ID
    HD = 0x44482323, // = ##HD
    [...]
}

The discriminant is four UTF-8 bytes. It would be nice to have an option to generate AsRef<str> using the discriminant interpreted as UTF-8 instead of using the type name.

Peternator7 commented 1 year ago

Hi @ericlagergren, this seems like a somewhat niche use-case so I'm not sure it's a good fit for strum. Most people would likely use an attribute to change how a variant is serialized.

ericlagergren commented 1 year ago

thanks for considering it!