Lymia / enumset

A library for compact bit sets containing enums.
Apache License 2.0
91 stars 35 forks source link

Make `EnumSet<T>` methods const if possible. #27

Open manuthambi opened 3 years ago

manuthambi commented 3 years ago

I would love to have some methods like intersection, union etc. const. Would help me avoid using lazy_static! or once_cell::Lazy at a bunch places in my code. This will probably require upping the MSRV. If you are open to this, I can send in a pull request.

Lymia commented 3 years ago

Yes, that'd be fine. I don't particularly want to maintain a strict MSRP, just a reasonable one that doesn't constantly push it for no good reason. I can also see if I can work on this myself.

Lymia commented 2 years ago

Do you have an idea of how to do this at a lower MSRV? This isn't even possible in stable right now because of trait bounds other than `Sized` on const fn parameters are unstable. What I can do is make an flag that requires nightly for const fns, but otherwise, not much I can do.

What I can do instead is try to update the enum_set! macro to support basic expressions and other constants.

manuthambi commented 2 years ago

Bummer! I didn't look too carefully into it, and assumed that it should be possible for inherent methods on stable.

Updating enum_set! would be pretty hacky, right? :( Perhaps it is better to just wait for more const stuff to be stabilized.

Thank you for looking into it!

Lymia commented 2 years ago

It would be, very much so. I'll still think about what I could do here, honestly...

Lymia commented 1 year ago

Reopening this since it's planned. Still blocked on rustc features - but may try some workarounds in the meanwhile.

Lymia commented 3 months ago

I've added some macros that should help with this. See the changelog:

This issue remains open because I don't think this can be properly solved until const fn supports this stuff entirely natively.