Skip to content

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

Open
@dbdr

Description

@dbdr

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"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.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