EnumBitFlags

A proc-macro crate for Rust that allows creating bit flags enums.

How to use: 1. First you need to this crate to your cargo.toml file: toml [dependencies] EnumBitFlags = "0.1.0"

  1. Then, you can use it in your Rust project like this: ```rs

    [EnumBitFlags]

enum MyFlags { Flag1 = 0x0001, Flag2 = 0x0002, Flag_3 = 0x0004 }

fn main() { let flags = MyFlags::Flag1 | MyFlags::Flag2;

// check if a flag is set (via .contains(...) method) if flags.contains(MyFlags::Flag1) { println!("Flag1 is present"); }

// check if a flag is set (via AND operation) if (flags & MyFlags::Flag2) == MyFlags::Flag2 { println!("Flag_2 is present"); } } ```

Arguments

EnumBitFlags supports various arguments that provide additional information on how to build the enum. Arguments are specified in the EnumBitFlags arguments with the following format: key=value,key=value,.... Alternativelly, you can use : instead of = (key:value, key:value....)

Methods

Every EnumBitFlags has several methods that can be used to easily manipulate and chek bits status:

|Method |Description| |--------------------------|-----------| |obj.contains(mask) |Returns true if all set bits from the mask are present in the object, or false otherwise| |obj.containsone(mask)|Returns true if at least one bit from the mask is present in the object, or false otherwise| |obj.clear() |Clears all bits from the current object| |obj.isempty() |Returns true if not bits are set, false otherwise| |obj.remove(mask) |Removes all set flags from the mask| |obj.set(mask) |Set all bits from the mask|