use bitflags::bitflags;
#[cfg(test)]
mod tests;
bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Attribute: u8 {
const WRITABLE = 0b0000_0001;
const ENUMERABLE = 0b0000_0010;
const CONFIGURABLE = 0b0000_0100;
const READONLY = 0b0000_0000;
const NON_ENUMERABLE = 0b0000_0000;
const PERMANENT = 0b0000_0000;
}
}
impl Attribute {
#[inline]
pub fn clear(&mut self) {
*self.0.bits_mut() = 0;
}
#[inline]
pub fn set_writable(&mut self, value: bool) {
if value {
*self |= Self::WRITABLE;
} else {
*self |= *self & !Self::WRITABLE;
}
}
#[inline]
#[must_use]
pub const fn writable(self) -> bool {
self.contains(Self::WRITABLE)
}
#[inline]
pub fn set_enumerable(&mut self, value: bool) {
if value {
*self |= Self::ENUMERABLE;
} else {
*self |= *self & !Self::ENUMERABLE;
}
}
#[inline]
#[must_use]
pub const fn enumerable(self) -> bool {
self.contains(Self::ENUMERABLE)
}
#[inline]
pub fn set_configurable(&mut self, value: bool) {
if value {
*self |= Self::CONFIGURABLE;
} else {
*self |= *self & !Self::CONFIGURABLE;
}
}
#[inline]
#[must_use]
pub const fn configurable(self) -> bool {
self.contains(Self::CONFIGURABLE)
}
}
impl Default for Attribute {
fn default() -> Self {
Self::READONLY | Self::NON_ENUMERABLE | Self::PERMANENT
}
}