How to use bitflags crate in Rust bit flags

Define a type-safe bitfield in Rust using the bitflags! macro to manage multiple boolean states as a single integer value.

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));
}