use crate::{Debug, FmtResult, Formatter};
#[doc = crate::_tags!(fmt debug)]
#[doc = crate::_doc_meta!{location("text/fmt")}]
#[rustfmt::skip]
pub trait DebugExt {
type Ctx;
fn fmt_with(&self, f: &mut Formatter, ctx: &Self::Ctx) -> FmtResult<()>;
fn debug_with<'a>(&'a self, ctx: &'a Self::Ctx) -> DebugWith<'a, Self> where Self: Sized {
DebugWith::new(self, ctx)
}
}
pub struct DebugWith<'a, T: DebugExt + ?Sized> {
value: &'a T,
ctx: &'a T::Ctx,
}
impl<'a, T: DebugExt + ?Sized> DebugWith<'a, T> {
pub const fn new(value: &'a T, ctx: &'a T::Ctx) -> Self {
Self { value, ctx }
}
}
impl<T: DebugExt + ?Sized> Debug for DebugWith<'_, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult<()> {
self.value.fmt_with(f, self.ctx)
}
}