Skip to content

Can not have an impl block for BitFlags<MyFlags> #61

Description

@de-vri-es

Because the BitFlags type comes from the enumflags2 crate, we can not add our own impl blocks for it or impl traits for it.

Would you be interested in an additional macro that allows you to define your own BitFlags type for a specific BitFlag enum?

#[bitflags]
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq)]
enum Flags {
    A = 0b0001,
    B = 0b0010,
    C, // unspecified variants pick unused bits automatically
    D = 0b1000,
}

#[flagset(Flags)]
struct Status;

// Yaay, we can do this:
impl Status {
  pub fn priority(&self) -> u8 {
     if self.contains(Flags::A) {
       1
     } else {
       2
     }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions