Repository navigation
refactor: Centralize generating the actual impl in the Implementation struct - #561
Merged
Merged
Conversation
Kriskras99
force-pushed
the
refactor/derive
branch
from
June 22, 2026 19:47
10792bd to
d8b9dfd
Compare
Member
|
@Kriskras99 This needs resolving of conflicts. |
Kriskras99
force-pushed
the
refactor/derive_implementation
branch
from
June 23, 2026 19:15
c601ca9 to
8bf4969
Compare
Contributor
Author
|
@martin-g Thanks for the headsup, is fixed now! |
martin-g
reviewed
Jun 24, 2026
| let default_value = default_enum_variant(data_enum, ident_span)?; | ||
| if data.variants.iter().all(|v| Fields::Unit == v.fields) { | ||
| let default_value = default_enum_variant(&data, input_span)?; | ||
| let default = preserve_optional(default_value); |
Member
There was a problem hiding this comment.
I wonder should container_attrs.rename_all be used also for the default value ?!
Contributor
Author
There was a problem hiding this comment.
Yes it should! This did cause a kind of snowball effect as to fix this:
- I needed the
serde_json::Valueinstead of aTokenStream - Needed to restructure the plain enum code
- Decided to also implement a
ValuetoTokenStreamfunction so we don't need to parse at runtime - I also made the serializer less struct (but keeping a fast path!), allowing
skipto work on enum variants
| Ok(( | ||
| field_to_schema_expr(&field, attrs.with.clone())?, | ||
| field_to_record_fields_expr(&field, attrs.with)?, | ||
| let field_default_expr = if container_attrs.default.is_none() { |
Member
There was a problem hiding this comment.
Hm. If there is no container default then use the field's default. Shouldn't the field's default overwrite the container's one ?
Contributor
Author
There was a problem hiding this comment.
I think you're right, and even stricter: I don't think default should be allowed as a container attribute on a transparent struct, so I've added it to the deny list.
…ion` struct This makes it clearer how everything fits together, and allows extending shared logic further (for example, adding generated tests). And because it is not a `TokenStream`, accidentally returning only a schema expression instead of the entire implementation results in a compilation error.
- Only allow the default attribute on the field of a transparent struct - Improve the plain enum schema generation - Skipped variants are now actually skipped - The container default attribute is used first, then comes the variant default attribute - `serde_json::Value`s are now constructed instead of parsed at runtime
Kriskras99
force-pushed
the
refactor/derive_implementation
branch
from
June 26, 2026 06:19
d5b14dc to
c626294
Compare
martin-g
reviewed
Jun 26, 2026
martin-g
approved these changes
Jun 26, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes it clearer how everything fits together, and allows extending shared logic further (for example, adding generated tests). And because it is not a
TokenStream, accidentally returning only a schema expression instead of the entire implementation results in a compilation error.This also fixes an issue where you couldn't override the
field_defaultimplementation for a transparent struct via a field attribute.This should be the last refactor PR before the actual enum PRs