Bitmask-Enum
A bitmask enum attribute macro, to turn an enum into a bitmask.
A bitmask can have (un)signed integer types, the default type is usize
.
First created because I wanted something simple, evolved with inspiration from the bitflags crate, which might be something you want to take a look at.
use bitmask;
// usize
// u8
Example
use bitmask;
// It is possible to impl on the bitmask and use its bits field
// bitmask has const bitwise operator methods
const CONST_BM: Bitmask = Flag2.or;
Custom Values
You can assign any flag a custom value.
use bitmask;
Bitmask Config
It is possible to add custom bitmask config options via the #[bitmask_config(...)]
macro. (Just add it below the #[bitmask]
macro)
use bitmask;
Available Config Options
inverted_flags
=> Adds an inverted flag for every non-inverted flag to the bitmask.
If you need / can think of any other config option, feel free to suggest them and we can discuss implementing them.
Implemented Methods
// Returns the underlying bits of the bitmask.
const #type;
// Returns a bitmask that contains all values.
const ;
// Returns `true` if the bitmask contains all values.
const ;
// Returns a bitmask that does not contain any values.
const ;
// Returns `true` if the bitmask does not contain any values.
const ;
// Returns `true` if `self` intersects with any value in `other`,
// or if `other` does not contain any values.
// This is equivalent to `(self & other) != 0 || other == 0`.
const ;
// Returns `true` if `self` contains all values of `other`.
// This is equivalent to `(self & other) == other`.
const ;
// Constant bitwise operations.
const ;
const ;
const ;
const ;
Implemented Traits