Skip to content

Assist proposal: generate a as_variant() method for enum #7604

@bnjjj

Description

@bnjjj

Inspired by this assist #7562 I would like add an assist to generate method as_variant_name() a pattern I often use to quickly extract a variant from an enum.
Example:

enum Number {
    I64(i64),
    F64(f64),
}

output:

enum Number {
    I64(i64),
    F64(f64),
}

impl Number {
    pub fn as_i64(&self) -> Option<&i64> {
        // ....
    }
}

If you think it could be useful for developers let me know I would be happy to implement this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-assistsS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions