Closed
Description
Currently, the Debug of Chars
prints the underlying bytes, rather than the chars:
#![allow(unused)]
fn main() {
let s = String::from(" é 😀 ");
let c = s.chars();
dbg!("Debug of Chars: ", &c);
dbg!("Debug of each char: ");
for x in c {
dbg!(x);
}
}
Returns:
[src/main.rs:5] "Debug of Chars: " = "Debug of Chars: "
[src/main.rs:5] &c = Chars {
iter: Iter(
[
32,
195,
169,
32,
240,
159,
152,
128,
32,
],
),
}
[src/main.rs:6] "Debug of each char: " = "Debug of each char: "
[src/main.rs:8] x = ' '
[src/main.rs:8] x = 'é'
[src/main.rs:8] x = ' '
[src/main.rs:8] x = '😀'
[src/main.rs:8] x = ' '
As I was trying to work out what chars
was (whether it was unicode points or bytes or something else), the first output was v confusing - is there a reason we don't print something like the second case?
Would you take a PR to change this?
I couldn't find any previous discussion on this - #49283 was the closest I could find.