Rollup merge of #137772 - thaliaarchi:bstr-display, r=joshtriplett

Fix char count in `Display` for `ByteStr`

`ByteStr as Display` performs a byte count when a char count is required.

r? ```````````@joshtriplett```````````
This commit is contained in:
Michael Goulet
2025-03-06 12:22:16 -05:00
committed by GitHub

View File

@@ -151,7 +151,9 @@ impl fmt::Display for ByteStr {
}; };
let nchars: usize = self let nchars: usize = self
.utf8_chunks() .utf8_chunks()
.map(|chunk| chunk.valid().len() + if chunk.invalid().is_empty() { 0 } else { 1 }) .map(|chunk| {
chunk.valid().chars().count() + if chunk.invalid().is_empty() { 0 } else { 1 }
})
.sum(); .sum();
let padding = f.width().unwrap_or(0).saturating_sub(nchars); let padding = f.width().unwrap_or(0).saturating_sub(nchars);
let fill = f.fill(); let fill = f.fill();