How to create an empty() flagset?
Closed this issue · 6 comments
elmarco commented
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?
zeenix commented
I don't think you create empty flags, you need to use the BitFlags struct.
meithecatte commented
On Tue, Jun 16, 2020 at 02:16:52AM -0700, Marc-Andre Lureau wrote:
Hi
I might not have enough sleep:
```rust
#[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?
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#25
You might be looking for `BitFlags::empty()`.
elmarco commented
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() ?
meithecatte commented
Yeah, that's reasonable. In the meantime, note that you can often rely on type inference and just write BitFlags::empty()
, sans turbofish.
meithecatte commented
Resolved by #28