6}", 1" /> 6}", 1" /> 6}", 1"/>

Rust pretty print with alignment

51 Views Asked by At

Like {:0>6} for alignment of a normal debug or display print, is there a way to align a pretty print with {:#?} in Rust?

Tried:

println!("{:#?0>6}", 123);

Expected the output:

000123
1

There are 1 best solutions below

2
cafce25 On

Yes, you just have to use the correct syntax as specified in the documentation:

[[fill]align][sign]['#']['0'][width]['.' precision]type

i.e. # has to come after > wihch is your align and before 6 which is your width and the type (? for Debug) has to come last.

So for your example that would be:

println!("{:0>#6?}", 123);