Skip to content

Highlight default enum variant #2206

Closed
Closed
@omid

Description

@omid

Since Rust has introduced #[default], can we hightlight it in the doc?
Like this one:

#[derive(Default)]
enum Status {
    #[default]
    Active,
    Inactive,
}

For other type of default definition of enums, it can be hard! For example, the following code, can be hard:

#[derive(...)]
enum Status {
    Active,
    Inactive,
}

impl Default for Status {
    fn default() -> Self {
        serde::from_str("active").unwrap()
    }
}

or:

#[derive(...)]
enum Status {
    Active,
    Inactive,
}

impl Default for Status {
    fn default() -> Self {
        if env!("ENV") == "prod" {
            Self::Inactive
        } else {
            Self::Active
        }
    }
}

We can ignore these cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions