Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #958
ghost opened this issue Jul 23, 2020 · 1 comment · Fixed by #964
Closed
Tracked by #958

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

ghost opened this issue Jul 23, 2020 · 1 comment · Fixed by #964
Labels
c: export Component: export (mod export, derive) feature Adds functionality to the library
Milestone

Comments

@ghost
Copy link

ghost commented Jul 23, 2020

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.

@ghost ghost added feature Adds functionality to the library c: export Component: export (mod export, derive) labels Jul 23, 2020
@ghost ghost added this to the 0.9.1 milestone Jul 23, 2020
@ghost ghost removed this from the 0.9.2 milestone Dec 28, 2020
@ghost ghost added this to the 0.10 milestone Feb 3, 2021
@jacobsky
Copy link
Contributor

jacobsky commented May 13, 2021

As mentioned in the discord. I'm going to take a look at working on this issue.

@Bromeon Bromeon modified the milestones: v0.10, v0.10.1 Nov 1, 2021
@Bromeon Bromeon modified the milestones: v0.10.1, v0.10.2 Jul 16, 2022
@Bromeon Bromeon modified the milestones: v0.10.2, v0.11.x Oct 1, 2022
chitoyuu added a commit to chitoyuu/godot-rust that referenced this issue Oct 18, 2022
Adds the `#[variant(enum = "repr")]` and `#[variant(enum = "str")]`
item-level attribute to the Variant conversion derive macros for
fieldless enums.

- `#[variant(enum = "repr")]` - convert through the numeric type
  specified using `#[repr]`.
- `#[variant(enum = "str")]` - convert through string representations of
  the variant names.

WIP - do not merge! FromVariant implementations would conflict
with godot-rust#962.

Close godot-rust#546.
chitoyuu added a commit to chitoyuu/godot-rust that referenced this issue Oct 18, 2022
Adds the `#[variant(enum = "repr")]` and `#[variant(enum = "str")]`
item-level attribute to the Variant conversion derive macros for
fieldless enums.

- `#[variant(enum = "repr")]` - convert through the numeric type
  specified using `#[repr]`.
- `#[variant(enum = "str")]` - convert through string representations of
  the variant names.

WIP - do not merge! FromVariant implementations would conflict
with godot-rust#962.

Close godot-rust#546.
chitoyuu added a commit to chitoyuu/godot-rust that referenced this issue Oct 18, 2022
Adds the `#[variant(enum = "repr")]` and `#[variant(enum = "str")]`
item-level attribute to the Variant conversion derive macros for
fieldless enums.

- `#[variant(enum = "repr")]` - convert through the numeric type
  specified using `#[repr]`.
- `#[variant(enum = "str")]` - convert through string representations of
  the variant names.

WIP - do not merge! FromVariant implementations would conflict
with godot-rust#962.

Close godot-rust#546.
chitoyuu added a commit to chitoyuu/godot-rust that referenced this issue Oct 19, 2022
Adds the `#[variant(enum = "repr")]` and `#[variant(enum = "str")]`
item-level attribute to the Variant conversion derive macros for
fieldless enums.

- `#[variant(enum = "repr")]` - convert through the numeric type
  specified using `#[repr]`.
- `#[variant(enum = "str")]` - convert through string
  representations of
  the variant names.

Close godot-rust#546.
bors bot added a commit that referenced this issue Oct 19, 2022
964: Derive stringly and numeric ToVariant for fieldless enums r=Bromeon a=chitoyuu

Adds the `#[variant(enum = "repr")]` and `#[variant(enum = "str")]` item-level attribute to the Variant conversion derive macros for fieldless enums.

- `#[variant(enum = "repr")]` - convert through the numeric type specified using `#[repr]`.
- `#[variant(enum = "str")]` - convert through string representations of the variant names.

Close #546.

Co-authored-by: Chitose Yuuzaki <[email protected]>
@bors bors bot closed this as completed in 3fb94a2 Oct 19, 2022
@chitoyuu chitoyuu modified the milestones: v0.11.x, v0.11.1 Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: export Component: export (mod export, derive) feature Adds functionality to the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants