enumset icon indicating copy to clipboard operation
enumset copied to clipboard

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

Open manuthambi opened this issue 4 years ago • 6 comments

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.

manuthambi avatar Sep 10 '21 16:09 manuthambi

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 avatar Oct 22 '21 00:10 Lymia

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.

Lymia avatar Nov 03 '21 02:11 Lymia

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!

manuthambi avatar Nov 03 '21 19:11 manuthambi

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

Lymia avatar Nov 04 '21 22:11 Lymia

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

Lymia avatar Mar 21 '23 17:03 Lymia

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

  • https://github.com/Lymia/enumset/blob/main/RELEASES.md#version-115-2024-07-22

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

Lymia avatar Jul 22 '24 21:07 Lymia