meithecatte/enumflags2

How to create an empty() flagset?

Closed this issue · 6 comments

Hi

I might not have enough sleep:

#[repr(u32)]
#[derive(BitFlags, Debug, PartialEq, Copy, Clone)]
pub enum RequestNameFlags {
    AllowReplacement = 0x01,
    ReplaceExisting = 0x02,
    DoNotQueue = 0x04,
}

How to crate an empty flag set? I am looking for RequestNameFlags::empty(), but I can't find it.

Do I need to have an expicit 0 value in the enum?

I don't think you create empty flags, you need to use the BitFlags struct.

Ok, got it. I had wrong assumptions about potential values of RequestNameFlags, it is actually BitFlags<RequestNameFlags> that can take various bitflags values.

BitFlags<RequestNameFlags>::emtpy() is a bit inconvenient. Can't the derive macro implement RequestNameFlags::empty() ?

Yeah, that's reasonable. In the meantime, note that you can often rely on type inference and just write BitFlags::empty(), sans turbofish.

Resolved by #28