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

Improve FromMeta implementation for enums #260

Merged
merged 14 commits into from
Jan 19, 2024

Conversation

davidsemakula
Copy link
Contributor

@davidsemakula davidsemakula commented Dec 28, 2023

Improves FromMeta implementation for enums

  • Properly implement unit arms in FromMeta::from_list to provide a consistent API for heterogenous enums that include a mix of unit, newtype and struct variants (see included test for an example).
  • Add #[darling(word)] for unit enum variants (See Add #[darling(word)] for enum variants #63).
  • Adds tests for behavior of FromMeta implementation for enums.

tests/from_meta.rs Outdated Show resolved Hide resolved
core/src/codegen/from_meta_impl.rs Outdated Show resolved Hide resolved
tests/from_meta.rs Outdated Show resolved Hide resolved
@davidsemakula
Copy link
Contributor Author

I'm working on implementing support for #[darling(word)] syntax

core/src/options/input_variant.rs Outdated Show resolved Hide resolved
core/src/codegen/from_meta_impl.rs Show resolved Hide resolved
core/src/codegen/from_meta_impl.rs Outdated Show resolved Hide resolved
core/src/codegen/from_meta_impl.rs Outdated Show resolved Hide resolved
Copy link
Owner

@TedDriggs TedDriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very excited about where this is heading; thank you for the latest updates. Feedback is now starting to get more specific, so I think we're closing in on readiness to merge.

core/src/codegen/from_meta_impl.rs Outdated Show resolved Hide resolved
core/src/options/input_variant.rs Show resolved Hide resolved
core/src/options/from_meta.rs Outdated Show resolved Hide resolved
core/src/options/from_meta.rs Outdated Show resolved Hide resolved
tests/compile-fail/duplicate_word_accross_variants.rs Outdated Show resolved Hide resolved
tests/compile-fail/duplicate_word_accross_variants.rs Outdated Show resolved Hide resolved
@davidsemakula
Copy link
Contributor Author

LMK if I should squash the commits 🙂

Copy link
Owner

@TedDriggs TedDriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only remaining items are:

  1. Deciding if this is the best name for this attribute. I thought it was originally (and I still don't think default is appropriate), but I am now worrying that word is too cryptic.
  2. Updating the CHANGELOG
  3. Updating the README

core/src/options/input_variant.rs Show resolved Hide resolved
@TedDriggs
Copy link
Owner

LMK if I should squash the commits 🙂

I think we're very close to the squash point.

@davidsemakula
Copy link
Contributor Author

I'll work on the changelog and readme updates tomorrow.

  1. Deciding if this is the best name for this attribute. I thought it was originally (and I still don't think default is appropriate), but I am now worrying that word is too cryptic.

Agreed, default would be confusing and word is a bit cryptic, but I don't have a better suggestion at this point. May be the more verbose from_word?

@davidsemakula
Copy link
Contributor Author

I updated the changelog. But I don't think I can update the readme to introduce and describe #[darling(word)] succinctly, can you take that part? I'm guessing it should be a bullet point under Features?

@TedDriggs
Copy link
Owner

In the absence of a README entry, we could consider an example that includes several features of a heterogeneous enum. Maybe replicate one of the tests over to the examples and add some comments to show what's going on?

@davidsemakula
Copy link
Contributor Author

Sounds good, I'll work on an example 👍

@davidsemakula
Copy link
Contributor Author

In the absence of a README entry, we could consider an example that includes several features of a heterogeneous enum. Maybe replicate one of the tests over to the examples and add some comments to show what's going on?

Added an example.

@davidsemakula
Copy link
Contributor Author

Pinging @TedDriggs

Copy link
Owner

@TedDriggs TedDriggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor changes left, then we're ready to merge!

Apologies for the delayed review, I was traveling last week and getting caught up at work this week.

core/src/options/from_meta.rs Outdated Show resolved Hide resolved
core/src/options/from_meta.rs Outdated Show resolved Hide resolved
core/src/options/input_variant.rs Show resolved Hide resolved
core/src/options/mod.rs Outdated Show resolved Hide resolved
@TedDriggs TedDriggs merged commit 6118a83 into TedDriggs:master Jan 19, 2024
12 checks passed
@davidsemakula davidsemakula deleted the from-meta-enum branch January 19, 2024 20:16
@davidsemakula
Copy link
Contributor Author

@TedDriggs can we get this published on crates.io when you have some time?
If I can do anything to help that process along, LMK 🙂

@TedDriggs
Copy link
Owner

TedDriggs commented Jan 25, 2024 via email

@TedDriggs
Copy link
Owner

v0.20.4 is now live.

@davidsemakula
Copy link
Contributor Author

Awesome! Thanks for taking the time to review this PR 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants