num_enum
num_enum copied to clipboard
Provide AsRef<Primitive> implementation
I am curious if you would be interested in providing a derive implementation to allow AsRef<Primitive>
. I have found when attempting to use this crate with some of the standard collections can start to get complicated. It would be nice to have a way to return a &'static Primitive
from any given instance of Enum
. I threw together a POC of what this might look like here. If you are interested in change I can open this PR against the main branch.
Thanks for this awesome crate!
Hello! Thanks for the thoughts and POC! I think implementation-wise, that looks pretty reasonable. I'm curious if you have an example or two of where you've needed this in real code - I haven't really hit such a need, and I can kind of imagine the shape of where it may be useful but not quite a full use-case.
Either way, feel free to put together a PR :)
A couple of questions on the code itself:
- Should be add an explicit
'static
lifetime to the returned refs? - Can you add a section to the root README.md basically duplicating the rustdoc from
derive_as_ref_primitive
?
Thanks again!