From: Ian Jackson Date: Sun, 27 Mar 2022 12:54:01 +0000 (+0100) Subject: Mutex debug: Use Debug for DebugIdentify, not Display X-Git-Tag: otter-1.0.0~104 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=87e8cdc3292db7db17ba3497ee651a51e3b80155;p=otter.git Mutex debug: Use Debug for DebugIdentify, not Display This will make the types useable with dbg!. Signed-off-by: Ian Jackson --- diff --git a/src/debugmutex.rs b/src/debugmutex.rs index 46c532ab..8caa704c 100644 --- a/src/debugmutex.rs +++ b/src/debugmutex.rs @@ -25,14 +25,14 @@ impl<'g,T> DerefMut for MutexGuard<'g,T> where T: DebugIdentify { fn deref_mut(&mut self) -> &mut T { &mut *self.0 } } -pub struct DisplayFormatter(F); -impl Display for DisplayFormatter -where F: Fn(&mut fmt::Formatter) -> fmt::Result { +pub struct DebugFormatter(C); +impl Debug for DebugFormatter +where C: for<'f,'ff> Fn(&'f mut fmt::Formatter<'ff>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0(f) } } -pub struct DisplayDebugIdentify<'t,T>(&'t T) where T: DebugIdentify; -impl Display for DisplayDebugIdentify<'_,T> where T: DebugIdentify { +pub struct DebugDebugIdentify<'t,T>(&'t T) where T: DebugIdentify; +impl Debug for DebugDebugIdentify<'_,T> where T: DebugIdentify { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.debug_identify(f) } @@ -50,13 +50,13 @@ pub trait DebugIdentify { impl DebugIdentify for Option where T: DebugIdentify { #[throws(fmt::Error)] fn debug_identify_type(f: &mut fmt::Formatter) { - write!(f, "Option<{}>", DisplayFormatter(T::debug_identify_type))?; + write!(f, "Option<{:?}>", DebugFormatter(T::debug_identify_type))?; } #[throws(fmt::Error)] fn debug_identify(&self, f: &mut fmt::Formatter) { match self { - None => write!(f, "None<{}>", DisplayFormatter(T::debug_identify_type))?, + None => write!(f, "None<{:?}>", DebugFormatter(T::debug_identify_type))?, Some(t) => t.debug_identify(f)?, } } @@ -65,7 +65,7 @@ impl DebugIdentify for Option where T: DebugIdentify { impl DebugIdentify for VecDeque where T: DebugIdentify { #[throws(fmt::Error)] fn debug_identify_type(f: &mut fmt::Formatter) { - write!(f, "VecDeque<{}>", DisplayFormatter(T::debug_identify_type))?; + write!(f, "VecDeque<{:?}>", DebugFormatter(T::debug_identify_type))?; } }