// SPDX-License-Identifier: MIT use std::fmt; pub struct CStrFormat<'a>(pub &'a [u8]); impl<'a> fmt::Debug for CStrFormat<'a> { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self, f) } } impl<'a> fmt::Display for CStrFormat<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let s = crate::from_c_str(self.0); fmt::Debug::fmt(&s, f) } } pub struct HexFormat(pub T); impl fmt::Debug for HexFormat { #[inline] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self, f) } } impl fmt::Display for HexFormat { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "0x{:x}", self.0) } } pub struct StraightFormat(pub T); impl fmt::Debug for StraightFormat { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{:?}", self.0) } } impl fmt::Display for StraightFormat { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.0) } }