use core::ops::{BitAnd, BitOr};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Role {
None,
Button,
Text,
TextEntry,
Container,
}
impl Role {
#[must_use]
const fn mask(self) -> RoleSet {
match self {
Self::None => RoleSet(0),
Self::Button => RoleSet(1 << 0),
Self::Text => RoleSet(1 << 1),
Self::TextEntry => RoleSet(1 << 2),
Self::Container => RoleSet(1 << 3),
}
}
}
impl BitOr for Role {
type Output = RoleSet;
fn bitor(self, rhs: Self) -> Self::Output {
self.mask() | rhs.mask()
}
}
impl BitAnd for Role {
type Output = RoleSet;
fn bitand(self, rhs: Self) -> Self::Output {
self.mask() & rhs.mask()
}
}
impl From<Role> for RoleSet {
fn from(value: Role) -> Self {
value.mask()
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RoleSet(u16);
impl RoleSet {
#[must_use]
pub const fn any() -> Self {
Self(u16::MAX)
}
#[must_use]
pub const fn empty() -> Self {
Self(0)
}
#[must_use]
pub const fn contains(self, role: Role) -> bool {
self.0 & role.mask().0 != 0
}
}
impl BitOr for RoleSet {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
impl BitAnd for RoleSet {
type Output = Self;
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}