use std::fmt::Display;
pub trait DisplayExt: Display + Sized {
fn println(self, msg: impl Display) -> Self {
println!("{msg}: {self}");
self
}
fn eprintln(self, msg: impl Display) -> Self {
eprintln!("{msg}: {self}");
self
}
fn println_dbg(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
println!("{msg}: {self}");
self
}
fn eprintln_dbg(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
eprintln!("{msg}: {self}");
self
}
}
impl<T: Display + Sized> DisplayExt for T {}
pub trait DebugExt: std::fmt::Debug + Sized {
fn dprintln(self, msg: impl Display) -> Self {
println!("{msg}: {self:?}");
self
}
fn deprintln(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
eprintln!("{msg}: {self:?}");
self
}
fn dprintln_dbg(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
println!("{msg}: {self:?}");
self
}
fn deprintln_dbg(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
eprintln!("{msg}: {self:?}");
self
}
fn dpprintln(self, msg: impl Display) -> Self {
println!("{msg}: {self:#?}");
self
}
fn depprintln(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
eprintln!("{msg}: {self:#?}");
self
}
fn dpprintln_dbg(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
println!("{msg}: {self:#?}");
self
}
fn depprintln_dbg(self, msg: impl Display) -> Self {
#[cfg(debug_assertions)]
eprintln!("{msg}: {self:#?}");
self
}
fn dbg(self) -> Self {
dbg!(self)
}
fn dbg_dbg(self) -> Self {
#[cfg(debug_assertions)]
dbg!(&self);
self
}
fn dbg_tagged(self, tag: &str) -> Self {
dbg!(tag, &self);
self
}
fn dbg_tagged_dbg(self, tag: &str) -> Self {
#[cfg(debug_assertions)]
dbg!(tag, &self);
self
}
}
impl<T: std::fmt::Debug> DebugExt for T {}