#[repr(C)]
#[derive(Debug, Eq, PartialEq)]
pub struct PropertyAttribute(u32);
pub const NONE: PropertyAttribute = PropertyAttribute(0);
pub const READ_ONLY: PropertyAttribute = PropertyAttribute(1);
pub const DONT_ENUM: PropertyAttribute = PropertyAttribute(2);
pub const DONT_DELETE: PropertyAttribute = PropertyAttribute(4);
impl PropertyAttribute {
pub fn is_none(&self) -> bool {
*self == NONE
}
pub fn is_read_only(&self) -> bool {
self.has(READ_ONLY)
}
pub fn is_dont_enum(&self) -> bool {
self.has(DONT_ENUM)
}
pub fn is_dont_delete(&self) -> bool {
self.has(DONT_DELETE)
}
fn has(&self, that: Self) -> bool {
let Self(lhs) = self;
let Self(rhs) = that;
0 != lhs & rhs
}
}
impl Default for PropertyAttribute {
fn default() -> Self {
NONE
}
}
impl std::ops::Add for PropertyAttribute {
type Output = Self;
fn add(self, Self(rhs): Self) -> Self {
let Self(lhs) = self;
Self(lhs + rhs)
}
}
#[test]
fn test_attr() {
assert!(NONE.is_none());
assert!(!NONE.is_read_only());
assert!(!NONE.is_dont_enum());
assert!(!NONE.is_dont_delete());
assert!(!READ_ONLY.is_none());
assert!(READ_ONLY.is_read_only());
assert!(!READ_ONLY.is_dont_enum());
assert!(!READ_ONLY.is_dont_delete());
assert!(!DONT_ENUM.is_none());
assert!(!DONT_ENUM.is_read_only());
assert!(DONT_ENUM.is_dont_enum());
assert!(!DONT_ENUM.is_dont_delete());
assert!(!DONT_DELETE.is_none());
assert!(!DONT_DELETE.is_read_only());
assert!(!DONT_DELETE.is_dont_enum());
assert!(DONT_DELETE.is_dont_delete());
assert_eq!(NONE, Default::default());
assert_eq!(READ_ONLY, NONE + READ_ONLY);
let attr = READ_ONLY + DONT_ENUM;
assert!(!attr.is_none());
assert!(attr.is_read_only());
assert!(attr.is_dont_enum());
assert!(!attr.is_dont_delete());
}