I'm looking to 0-pad a string before I display it to the user, e.g.
let x = 1234;
println!("{:06}", x); // "001234"
However, I'd like the length of the output string to be variable, e.g. it could be set by a command line parameter from the user:
let x = 1234;
let width = 6;
println!("{:0*}", width, x); //fails to compile
// error: invalid format string: expected `'}'`, found `'*'`
Unlike precision, it doesn't seem that 0-padding supports the *
for specifying a width.
I'm not looking for solutions that involve manually padding, because it seems awkward to re-implement part of std::fmt
.