use core::fmt::Debug;
use core::marker::PhantomData;
use crate::MayDebug;
use super::Neu;
pub struct Not<U, T>
where
U: Neu<T>,
{
unit: U,
marker: PhantomData<T>,
}
impl<U, T> Debug for Not<U, T>
where
U: Neu<T> + Debug,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("Not").field("unit", &self.unit).finish()
}
}
impl<U, T> Default for Not<U, T>
where
U: Neu<T> + Default,
{
fn default() -> Self {
Self {
unit: Default::default(),
marker: Default::default(),
}
}
}
impl<U, T> Clone for Not<U, T>
where
U: Neu<T> + Clone,
{
fn clone(&self) -> Self {
Self {
unit: self.unit.clone(),
marker: self.marker,
}
}
}
impl<U, T> Copy for Not<U, T> where U: Neu<T> + Copy {}
impl<U, T> Not<U, T>
where
U: Neu<T>,
{
pub const fn new(unit: U) -> Self {
Self {
unit,
marker: PhantomData,
}
}
pub const fn unit(&self) -> &U {
&self.unit
}
pub const fn unit_mut(&mut self) -> &mut U {
&mut self.unit
}
pub fn set_unit(&mut self, unit: U) -> &mut Self {
self.unit = unit;
self
}
}
impl<U, T> Neu<T> for Not<U, T>
where
T: MayDebug,
U: Neu<T>,
{
#[inline(always)]
fn is_match(&self, other: &T) -> bool {
let ret = !self.unit.is_match(other);
crate::trace_retval!("Not", other, ret)
}
fn min_length(&self) -> usize {
self.unit.min_length()
}
}
pub const fn not<T, U: Neu<T>>(unit: U) -> Not<U, T> {
Not::new(unit)
}