format is utility crate to make it easier to work with the Formatter.
It defines format wrappers (Debug
, Display
, Binary
, ...) which implements respectively traits. For example LowerHex
impl fmt::LowerHex
, fmt::Display
and fmt::Debug
traits. Also it defines lazy_format
helper macro.
Examle usage:
struct Foo(usize);
impl Debug for Foo {
fn fmt(&self, f: &mut Formatter) -> Result {
let alternate = f.alternate();
let bar = lazy_format!(|f| if alternate {
write!(f, "{:#x}", self.0)
} else {
write!(f, "{:x}", self.0)
});
f.debug_tuple("Foo").field(&bar).finish()
}
}
Solves some problem like this