use crate::private::Context;
pub trait Sealed {}
pub trait FlagInternal: Flag {
fn set(&mut self, _cx: &Context);
}
#[diagnostic::on_unimplemented(message = "`{Self}` cannot be used as the target of `inverse_of`")]
pub trait InvertibleFlag: Flag {
fn unset(&mut self, _cx: &Context);
}
impl Sealed for bool {}
impl FlagInternal for bool {
#[inline]
fn set(&mut self, _cx: &Context) {
*self = true;
}
}
impl InvertibleFlag for bool {
#[inline]
fn unset(&mut self, _cx: &Context) {
*self = false;
}
}
impl Sealed for Option<bool> {}
impl FlagInternal for Option<bool> {
#[inline]
fn set(&mut self, _cx: &Context) {
*self = Some(true);
}
}
impl InvertibleFlag for Option<bool> {
#[inline]
fn unset(&mut self, _cx: &Context) {
*self = Some(false);
}
}
pub trait Flag: Default + Sealed {}
impl Flag for bool {}
impl Flag for Option<bool> {}
macro_rules! impl_ints {
($($int:ty),*) => {
$(
impl Sealed for $int {}
impl FlagInternal for $int {
#[inline]
fn set(&mut self, _cx: &Context) {
*self = self.saturating_add(1);
}
}
impl InvertibleFlag for $int {
#[inline]
fn unset(&mut self, _cx: &Context) {
*self = self.saturating_sub(1);
}
}
impl Flag for $int {}
)*
};
}
impl_ints!(
u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize
);