Skip to content

0x prefix for hexadecimal and pretty-printed Debug cannot be specified separately in std::fmt #75766

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

Open
dbdr opened this issue Aug 21, 2020 · 0 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@dbdr
Copy link

dbdr commented Aug 21, 2020

In std::fmt:

  • x prints integers in hexadecimal format
  • #x prefixes hexadecimal numbers with a 0x
  • #? pretty-prints the Debug formatting (e.g. one vector element per line)

The problem is that those are not orthogonal. #x? will both add 0x and pretty-print. There does not seem to be a way to get one behavior without the other.

    let v = [11];
    /*
        [11]
    */
    println!("{:?}", v);
    /*
        [
            11,
        ]
    */
    println!("{:#?}", v);
    /*
        [b]
    */
    println!("{:x?}", v);
    /*
        [
            0xb,
        ]
    */
    println!("{:#x?}", v);
    /*
        [
            b,
        ]
    */
    // ??
    /*
        [0xb]
    */
    // ??

Could the # modifier apply only to the closest type, so that #x?, x#? and #x#? could be used to denote each case? (this would cause an output change for #x?). Alternatively, another letter to denote "hexadecimal with 0x prefix"?

@dbdr dbdr added the C-bug Category: This is a bug. label Aug 21, 2020
@dbdr dbdr changed the title 0x prefix for hexadecimal and pretty-printing cannot be specified separately in std::fmt 0x prefix for hexadecimal and pretty-printed Debug cannot be specified separately in std::fmt Aug 21, 2020
@jonas-schievink jonas-schievink added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants