use crate::{spec::Wrapper, Cmp, CmpDisplay, CmpError}; use core::fmt; #[repr(transparent)] #[derive(Copy, Clone)] pub struct DebugWrapper(pub T); #[repr(transparent)] #[derive(Copy, Clone)] pub struct NoDebugWrapper(pub T); impl< Lhs: ?Sized + core::ops::Deref, Rhs: ?Sized + core::ops::Deref, C: CmpError, > CmpError, Wrapper, Wrapper> for CmpDebugWrapper { type Error = CmpDebugWrapper; } impl< Lhs: ?Sized + core::ops::Deref, Rhs: ?Sized + core::ops::Deref, C, E: CmpDisplay, > CmpDisplay, Wrapper, Wrapper> for CmpDebugWrapper { fn fmt( &self, cmp: &CmpDebugWrapper, lhs: &Wrapper, lhs_source: &str, lhs_debug: &dyn fmt::Debug, rhs: &Wrapper, rhs_source: &str, rhs_debug: &dyn fmt::Debug, f: &mut fmt::Formatter, ) -> fmt::Result { self.0.fmt( &cmp.0, &*lhs.0, lhs_source, lhs_debug, &*rhs.0, rhs_source, rhs_debug, f, ) } } impl< Lhs: ?Sized + core::ops::Deref, Rhs: ?Sized + core::ops::Deref, C: Cmp, > Cmp, Wrapper> for CmpDebugWrapper { #[inline(always)] fn test(&self, lhs: &Wrapper, rhs: &Wrapper) -> Result<(), Self::Error> { self.0.test(&*lhs.0, &*rhs.0).map_err(CmpDebugWrapper) } } impl core::ops::Deref for DebugWrapper { type Target = T; #[inline] fn deref(&self) -> &Self::Target { &self.0 } } impl core::ops::Deref for NoDebugWrapper { type Target = T; #[inline] fn deref(&self) -> &Self::Target { &self.0 } } impl fmt::Debug for DebugWrapper { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl fmt::Debug for NoDebugWrapper { #[inline(always)] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "", core::any::type_name::(), self as *const _ as *const () ) } } pub struct DebugWrap; pub struct NoDebugWrap; impl DebugWrap { #[inline(always)] pub fn do_wrap(self, value: &T) -> &DebugWrapper { unsafe { &*(value as *const T as *const DebugWrapper) } } } impl NoDebugWrap { #[inline(always)] pub fn do_wrap(self, value: &T) -> &NoDebugWrapper { unsafe { &*(value as *const T as *const NoDebugWrapper) } } } #[repr(transparent)] #[derive(Copy, Clone)] pub struct CmpDebugWrapper(pub T); pub trait TryDebugWrap { type Wrap; fn wrap_debug(&self) -> Self::Wrap; } impl TryDebugWrap for &Wrapper { type Wrap = DebugWrap; #[inline] fn wrap_debug(&self) -> Self::Wrap { DebugWrap } } impl TryDebugWrap for Wrapper { type Wrap = NoDebugWrap; #[inline] fn wrap_debug(&self) -> Self::Wrap { NoDebugWrap } }