Crates.io | format |
lib.rs | format |
version | 0.2.4 |
source | src |
created_at | 2020-04-01 11:36:22.432704 |
updated_at | 2021-04-04 14:37:38.693697 |
description | A utility crate to make it easier to work with the formatter |
homepage | https://crates.io/crates/format |
repository | https://github.com/kgv/format |
max_upload_size | |
id | 225155 |
size | 26,300 |
A utility crate to make it easier to work with the formatter
Add dependency to your Cargo.toml
:
[dependencies]
format = "0.2"
and use lazy_format
macro:
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(&format_args!("{}", bar))
.finish()
}
}
or one of format type:
struct Foo(usize);
impl Debug for Foo {
fn fmt(&self, f: &mut Formatter) -> Result {
let alternate = f.alternate();
let bar = LowerHex(|f| {
if alternate {
write!(f, "{:#x}", self.0)
} else {
write!(f, "{:x}", self.0)
}
});
f.debug_tuple("Foo")
.field(&format_args!("{:x}", bar))
.finish()
}
}