Skip to content

Option to derive Variant conversion to and from primitives for fieldless enums #546

Closed
@ghost

Description

We can add an option to the variant attribute to achieve this. The API may look something like:

#[derive(ToVariant, FromVariant)]
#[variant(enum = "i64")]
enum Foo {
    A = 1,
    B = 2,
}

#[derive(ToVariant, FromVariant)]
#[variant(enum = "str")]
enum Bar {
    A,
    B,
}

...where Foo is converted to and from i64 values equal to the discriminant, and Bar is converted to and from strings representing the variant names.

Optionally, we might also add a derive macro for Export for these types that automatically generates the appropriate hints.

See also: #544.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: exportComponent: export (mod export, derive)featureAdds functionality to the library

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions