-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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.
FauxFaux, dwnusbaum, DianaNites, ian-h-chamberlain and eupn
Metadata
Metadata
Assignees
Labels
A-fmtArea: `core::fmt`Area: `core::fmt`C-bugCategory: This is a bug.Category: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.