-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing Debug of chars #62947
Comments
The first one is UTF-8 bytes. You see this because the #[derive(Clone, Debug)]
pub struct Chars<'a> {
iter: slice::Iter<'a, u8>
} Strictly speaking, since the bytes inside of The reason it doesn't display as individual chars is because it doesn't have individual (but then the solution seems to be to use I guess that, questionable concerns of efficiency aside, my main concern is simply that showing a list of individual chars would be... dishonest, I guess. |
Do |
No, they contain the same data. They're all just UTF-8 bytes. And the Suppose we are writing to STDOUT. On UNIX, the rust/src/libstd/sys/unix/stdio.rs Lines 27 to 30 in eedf6ce
rust/src/libstd/sys/unix/fd.rs Lines 109 to 116 in eedf6ce
I would imagine this is because the console on any UNIX platform almost certainly uses UTF-8.1 It is your terminal application that is then responsible for decoding these bytes and producing glyphs. Considering that UTF-8 dominates much of the web space as well, it's quite possible that even on the playground, these bytes are ultimately sent over the wire to your PC with minimal processing, where your browser is responsible for decoding and displaying them. On Windows, rust/src/libstd/sys/windows/stdio.rs Lines 76 to 84 in eedf6ce
and then Windows does whatever it does with those UTF-16 code units. (Quite likely, it hands them directly to the console, which is then responsible for decoding and displaying them) Footnotes
|
OK, so given that - is there still an objection to displaying the unicode characters for |
…hton Impl Debug for Chars Closes rust-lang#62947, making `Debug` more consistent with the struct's output and purpose Let me know any feedback!
…hton Impl Debug for Chars Closes rust-lang#62947, making `Debug` more consistent with the struct's output and purpose Let me know any feedback!
…hton Impl Debug for Chars Closes rust-lang#62947, making `Debug` more consistent with the struct's output and purpose Let me know any feedback!
…hton Impl Debug for Chars Closes rust-lang#62947, making `Debug` more consistent with the struct's output and purpose Let me know any feedback!
Currently, the Debug of
Chars
prints the underlying bytes, rather than the chars:Playground link
Returns:
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.
The text was updated successfully, but these errors were encountered: