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

Derive stringly and numeric ToVariant for fieldless enums #964

Merged
merged 1 commit into from
Oct 19, 2022

Conversation

chitoyuu
Copy link
Contributor

@chitoyuu chitoyuu commented 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.

Close #546.

@Bromeon Bromeon added feature Adds functionality to the library c: export Component: export (mod export, derive) labels Oct 18, 2022
@chitoyuu chitoyuu force-pushed the feature/primitive-enum branch from 3d59022 to 63fcc2e Compare October 19, 2022 08:32
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.
@chitoyuu chitoyuu force-pushed the feature/primitive-enum branch from 63fcc2e to 3fb94a2 Compare October 19, 2022 08:34
@chitoyuu chitoyuu marked this pull request as ready for review October 19, 2022 08:53
@chitoyuu chitoyuu changed the title WIP: Derive stringly and numeric ToVariant for fieldless enums Derive stringly and numeric ToVariant for fieldless enums Oct 19, 2022
@chitoyuu
Copy link
Contributor Author

Should be ready for review now!

@Bromeon
Copy link
Member

Bromeon commented Oct 19, 2022

Thanks a lot for this!

Maybe a small request for the future: if you have a refactoring in the same PR (here splitting Attr/AttrBuilder), it would help to separate it into 2 commits for review. Of course only if this doesn't need long git-rebasing after the fact 🙂

I also seems like the documentation for ToVariant is now a bit out-of-date, but maybe this can be updated in another pull request, to include changes over several related additions.

bors r+

@Bromeon Bromeon added this to the v0.11.x milestone Oct 19, 2022
@bors
Copy link
Contributor

bors bot commented Oct 19, 2022

Build succeeded:

@bors bors bot merged commit 28ff425 into godot-rust:master Oct 19, 2022
@chitoyuu
Copy link
Contributor Author

Ah yes, thanks for reminding me! Got a bit lazy with the rebase here. I'll make a PR for the docs later.

bors bot added a commit that referenced this pull request Oct 31, 2022
971: Add docs for the `#[variant(enum)]` attribute. r=Bromeon a=chitoyuu

Follow-up to #964

Co-authored-by: Chitose Yuuzaki <[email protected]>
@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 this pull request may close these issues.

Option to derive Variant conversion to and from primitives for fieldless enums
2 participants