Skip to content

Don’t print a space after an empty struct name with Formatter::debug_struct #88261

@EFanZh

Description

@EFanZh

I wish I can print a structure like an anonymous structure by specifying an empty structure name using Formatter::debug_struct, for example:

struct Item;

impl Debug for Item {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        f.debug_struct("").field("x", &2).finish()
    }
}

I expect format!("{:?}", Item) to be "{ x: 2 }", instead, I get " { x: 2 }".

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions