Use the bitflags! macro to define a type-safe wrapper around an integer that supports bitwise operations and flag combinations.
use bitflags::bitflags;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Permissions: u8 {
const READ = 0b00000100;
const WRITE = 0b00000010;
const EXECUTE = 0b00000001;
}
}
fn main() {
let read_write = Permissions::READ | Permissions::WRITE;
assert!(read_write.contains(Permissions::READ));
}