#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct Flags(pub u8);
impl Flags {
pub const EMPTY: Self = Self(0);
pub const ACK_ELICITING: Self = Self(1 << 0);
pub const REALTIME: Self = Self(1 << 1);
#[must_use]
pub const fn from_bits(bits: u8) -> Self {
Self(bits)
}
#[must_use]
pub const fn bits(self) -> u8 {
self.0
}
#[must_use]
pub const fn contains(self, other: Self) -> bool {
(self.0 & other.0) == other.0
}
#[must_use]
pub const fn union(self, other: Self) -> Self {
Self(self.0 | other.0)
}
}
#[cfg(test)]
mod tests {
use super::Flags;
#[test]
fn union_contains_combined_flags() {
let flags = Flags::ACK_ELICITING.union(Flags::REALTIME);
assert!(flags.contains(Flags::ACK_ELICITING));
assert!(flags.contains(Flags::REALTIME));
assert!(!flags.contains(Flags::from_bits(1 << 7)));
}
}