Open
Description
Consider the following println:
let msg = "Hello";
println!("(i,j,k): |{:30}|", msg);
This is using the width
parameter to ensure that the output occupies at least width
characters. (One can provide other arguments like fill/alignment to adjust the fill character or whether the output is left/right/center- alligned.) See docs here: https://doc.rust-lang.org/std/fmt/#width
In other words, it prints this (note the distance between the two occurrences of |
):
(i,j,k): |Hello |
So, the problem:
The Debug
trait seems to honor width
for numeric and pointer types, but not for other types.
For example:
println!("(i,j,k): |{:30?}|", msg);
does not necessarily put at least 30 characters between the two |
characters that it prints; in the case of msg
given above, it prints:
(i,j,k): |"Hello"|
Here is a playpen illustrating the problem on several inputs.