use core::fmt;
#[doc(hidden)]
pub struct FmtAbsent;
#[doc(hidden)]
pub struct Wrap<'a, T: ?Sized>(pub &'a T);
impl<T: fmt::Display + ?Sized> Wrap<'_, T> {
pub fn fmt_display(&self, f: &mut fmt::Formatter<'_>) -> Result<fmt::Result, FmtAbsent> {
Ok(fmt::Display::fmt(self.0, f))
}
}
impl<T: fmt::Debug + ?Sized> Wrap<'_, T> {
pub fn fmt_debug(&self, f: &mut fmt::Formatter<'_>) -> Result<fmt::Result, FmtAbsent> {
Ok(fmt::Debug::fmt(self.0, f))
}
pub fn fmt_debug_pretty(&self, f: &mut fmt::Formatter<'_>) -> Result<fmt::Result, FmtAbsent> {
Ok(write!(f, "{:#?}", self.0))
}
}
#[doc(hidden)]
pub trait DisplayFallback {
fn fmt_display(&self, _f: &mut fmt::Formatter<'_>) -> Result<fmt::Result, FmtAbsent> {
Err(FmtAbsent)
}
}
impl<T: ?Sized> DisplayFallback for Wrap<'_, T> {}
#[doc(hidden)]
pub trait DebugFallback {
fn fmt_debug(&self, _f: &mut fmt::Formatter<'_>) -> Result<fmt::Result, FmtAbsent> {
Err(FmtAbsent)
}
fn fmt_debug_pretty(&self, _f: &mut fmt::Formatter<'_>) -> Result<fmt::Result, FmtAbsent> {
Err(FmtAbsent)
}
}
impl<T: ?Sized> DebugFallback for Wrap<'_, T> {}