use crate::{BitFlags, BitFlag};
use core::marker::PhantomData;
pub struct ConstToken<T, N>(BitFlags<T, N>);
impl<T> BitFlags<T>
where
T: BitFlag,
{
pub const EMPTY: Self = BitFlags {
val: T::EMPTY,
marker: PhantomData,
};
pub const ALL: Self = BitFlags {
val: T::ALL_BITS,
marker: PhantomData,
};
pub const CONST_TOKEN: ConstToken<T, T::Numeric> = ConstToken(Self::ALL);
}
for_each_uint! { $ty $hide_docs =>
impl<T> BitFlags<T, $ty> {
#[must_use]
#[inline(always)]
$(#[$hide_docs])?
pub const unsafe fn from_bits_unchecked_c(
val: $ty, const_token: ConstToken<T, $ty>
) -> Self {
let _ = const_token;
BitFlags {
val,
marker: PhantomData,
}
}
#[must_use]
#[inline(always)]
$(#[$hide_docs])?
pub const fn from_bits_truncate_c(
bits: $ty, const_token: ConstToken<T, $ty>
) -> Self {
BitFlags {
val: bits & const_token.0.val,
marker: PhantomData,
}
}
#[must_use]
#[inline(always)]
$(#[$hide_docs])?
pub const fn union_c(self, other: Self) -> Self {
BitFlags {
val: self.val | other.val,
marker: PhantomData,
}
}
#[must_use]
#[inline(always)]
$(#[$hide_docs])?
pub const fn intersection_c(self, other: Self) -> Self {
BitFlags {
val: self.val & other.val,
marker: PhantomData,
}
}
#[must_use]
#[inline(always)]
$(#[$hide_docs])?
pub const fn not_c(self, const_token: ConstToken<T, $ty>) -> Self {
BitFlags {
val: !self.val & const_token.0.val,
marker: PhantomData,
}
}
#[inline(always)]
$(#[$hide_docs])?
pub const fn bits_c(self) -> $ty {
self.val
}
}
}