//! Format wrappers for Zebra use std::{fmt, ops}; /// Wrapper to override `Debug`, redirecting it to the `Display` impl. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DisplayToDebug(pub T); impl fmt::Debug for DisplayToDebug where T: fmt::Display, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } impl ops::Deref for DisplayToDebug { type Target = T; fn deref(&self) -> &Self::Target { &self.0 } } impl From for DisplayToDebug { fn from(t: T) -> Self { Self(t) } } /// Wrapper to override `Debug` to display a shorter summary of the type. /// /// For collections and exact size iterators, it only displays the /// collection/iterator type, the item type, and the length. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SummaryDebug(pub CollectionOrIter); impl fmt::Debug for SummaryDebug where CollectionOrIter: IntoIterator + Clone, ::IntoIter: ExactSizeIterator, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "{}<{}>, len={}", std::any::type_name::(), std::any::type_name::<::Item>(), self.0.clone().into_iter().len() ) } } impl ops::Deref for SummaryDebug { type Target = CollectionOrIter; fn deref(&self) -> &Self::Target { &self.0 } } impl From for SummaryDebug { fn from(collection: CollectionOrIter) -> Self { Self(collection) } } impl IntoIterator for SummaryDebug where CollectionOrIter: IntoIterator, { type Item = ::Item; type IntoIter = ::IntoIter; fn into_iter(self) -> Self::IntoIter { self.0.into_iter() } }