Macro powerfmt::smart_display::padded_width_of
source ยท macro_rules! padded_width_of { ($($t:tt)*) => { ... }; }
Expand description
Compute the width of multiple items while optionally declaring the options for each item.
let alpha = 0;
let beta = 1;
let gamma = 100;
let width = smart_display::padded_width_of!(
alpha, // use the default options
beta => width(2), // use the specified options
gamma => width(2) sign_plus(true), // use multiple options
);
assert_eq!(width, 7);
let formatted = format!("{alpha}{beta:2}{gamma:+2}");
assert_eq!(formatted.len(), width);
Supported options are:
Option | Method called |
---|---|
fill(char) | FormatterOptions::with_fill |
sign_plus(bool) | FormatterOptions::with_sign_plus |
sign_minus(bool) | FormatterOptions::with_sign_minus |
align(Alignment) | FormatterOptions::with_align |
width(usize) | FormatterOptions::with_width |
precision(usize) | FormatterOptions::with_precision |
alternate(bool) | FormatterOptions::with_alternate |
sign_aware_zero_pad(bool) | FormatterOptions::with_sign_aware_zero_pad |
If there are future additions to FormatterOptions
, they will be added to this macro as well.
Options may be provided in any order and will be called in the order they are provided. The
ordering matters if providing both sign_plus
and sign_minus
.