use std::{
fmt::Debug,
ops::{BitAnd, BitOr, BitXor},
};
macro_rules! wrap_bit_ops {
($bitstruct:tt) => {
impl BitAnd for $bitstruct {
type Output = Self;
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}
impl BitOr for $bitstruct {
type Output = Self;
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0 | rhs.0)
}
}
impl BitXor for $bitstruct {
type Output = Self;
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0 ^ rhs.0)
}
}
impl PartialEq for $bitstruct {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl Eq for $bitstruct {}
impl Debug for $bitstruct {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(format!("{:b}", self.0).as_str())
}
}
impl $bitstruct {
pub fn is_none(&self) -> bool {
self.0 == 0
}
pub fn null() -> Self {
Self(0)
}
}
};
}
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct BufferFlags(u8);
wrap_bit_ops!(BufferFlags);
impl BufferFlags {
pub const UNIFORM: Self = Self(0b001);
pub const TRANSFER: Self = Self(0b010);
pub const SYNCED: Self = Self(0b100);
}