Macro neli::impl_flags

source ·
macro_rules! impl_flags {
    ($(#[$outer:meta])* $vis:vis $name:ident, $type:ty, $bin_type:ty $(,)?) => { ... };
}
Expand description

Implement a container for bit flag enums where the set of flags will be condensed into a single value.

Usage

use neli::neli_enum;

#[neli_enum(serialized_type = "u16")]
pub enum MyFlags {
    ThisFlag = 1,
    ThatFlag = 2,
}

neli::impl_flags!(
    MyFlagSet,
    MyFlags,
    u16
);

This creates a struct called MyFlagSet that has the following autogenerated methods:

  • fn empty() -> Self
  • fn new(flags: &[MyFlags]) -> Self
  • fn set(&mut self, flag: MyFlags)
  • fn unset(&mut self, flag: &MyFlags)
  • fn contains(&self, flag: &MyFlags) -> bool
  • fn from_bitmask(bitmask: &IntType) -> Self

When the following example is serialized, all flags contained in the set at the time of serialization will be converted into u16s and bitwise or-ed.