num_enum icon indicating copy to clipboard operation
num_enum copied to clipboard

Provide AsRef<Primitive> implementation

Open FreeMasen opened this issue 1 year ago • 1 comments

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!

FreeMasen avatar Sep 06 '23 15:09 FreeMasen

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:

  1. Should be add an explicit 'static lifetime to the returned refs?
  2. Can you add a section to the root README.md basically duplicating the rustdoc from derive_as_ref_primitive?

Thanks again!

illicitonion avatar Sep 06 '23 22:09 illicitonion