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

Accept from_* methods as #[darling(...)] fields #320

Closed
TedDriggs opened this issue Jan 22, 2025 · 0 comments · Fixed by #323
Closed

Accept from_* methods as #[darling(...)] fields #320

TedDriggs opened this issue Jan 22, 2025 · 0 comments · Fixed by #323

Comments

@TedDriggs
Copy link
Owner

It's currently impossible to have a struct with a derived FromMeta impl that has custom behavior in the from_word or from_none cases. The only workaround is to use with on every field of that type, which is tiresome.

Based on the discussion in #313, this proposal would allow the deriving struct to specify a path (or closure) that replaces the body of the corresponding method.

This will require some validation to ensure these options aren't conflicting with generated impls; for example, from_word cannot be used with enums where word is in use.

Additionally, this will require new documentation and examples.

TedDriggs added a commit that referenced this issue Jan 22, 2025
This allows overriding how FromMeta-deriving types handle shorthand declarations or being absent altogether.

Previously, this was done using `with` on each field where the type was consumed, but that could cause attribute sprawl or inconsistent behavior when consuming the type.

This commit includes validations to avoid conflicts for unit structs, newtype structs, and enums that use the `word` variant-level attribute.

Fixes #320
TedDriggs added a commit that referenced this issue Jan 22, 2025
This allows overriding how FromMeta-deriving types handle shorthand declarations or being absent altogether.

Previously, this was done using `with` on each field where the type was consumed, but that could cause attribute sprawl or inconsistent behavior when consuming the type.

This commit includes validations to avoid conflicts for unit structs, newtype structs, and enums that use the `word` variant-level attribute.

Fixes #320
TedDriggs added a commit that referenced this issue Jan 22, 2025
This allows overriding how FromMeta-deriving types handle shorthand declarations or being absent altogether.

Previously, this was done using `with` on each field where the type was consumed, but that could cause attribute sprawl or inconsistent behavior when consuming the type.

This commit includes validations to avoid conflicts for unit structs, newtype structs, and enums that use the `word` variant-level attribute.

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

Successfully merging a pull request may close this issue.

1 participant