Skip to content

Allow usage of enum variant name in Display format #37

@NightEule5

Description

@NightEule5

I have an Displayed enum with a custom format on each variant, like this:

#[derive(Display)]
enum SomeEnum {
    #[display("valuea:{0}")]
    ValueA(String),
    #[display("valueb:{0}")]
    ValueB(String),
    #[display("valuec:{0}")]
    ValueC(String),
}

It'd be nice to make this more readable by using the lowercase term in the format, such as #[display("{lowercase}:{0}")] or #[display("{}:{0}", lowercase)]. A drawback of the former is ambiguity if the variant contains a lowercase field (positional format args don't appear to be accepted currently), so the latter is likely the preferred form.

Even better would be this:

#[derive(Display)]
#[display("{}:{0}", lowercase)]
enum SomeEnum {
    ValueA(String),
    ValueB(String),
    ValueC(String),
    #[display(lowercase)]
    Other // breaks above convention
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions