Skip to content

Confusing Debug of chars #62947

Closed
Closed
@max-sixty

Description

@max-sixty

Currently, the Debug of Chars prints the underlying bytes, rather than the chars:

Playground link

#![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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-iteratorsArea: IteratorsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions