I am binding LMDB, and it makes extensive use of C bit sets as flags.
I would like to create a zero-cost abstraction with Odin’s bit_set
.
For example lets take the following flags in (ported from header files):
Env_Flag :: enum c.uint {
NOFLAGS = 0,
FIXEDMAP = 0x01,
NOSUBDIR = 0x4000,
RDONLY = 0x20000,
WRITEMAP = 0x80000,
NOMETASYNC = 0x40000,
NOSYNC = 0x10000,
MAPASYNC = 0x100000,
NOTLS = 0x200000,
NOLOCK = 0x400000,
NORDAHEAD = 0x800000,
NOMEMINIT = 0x1000000,
PREVSNAPSHOT = 0x2000000,
}
I know that by doing the following I loose the bites value, and I would then need to check each flag manually, but how can I avoid that?
Flags := bit_set[Env_flags]
Is there a way to “cast” the set into an uint
without manually checking for the values?