feat(derive): add custom field for struct #2563
Closed
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.
Hi! It is not infrequently that I find myself needing to compute a custom
field that is only present on serialization and is calculated off of another
one of the struct's fields. Usually, I'll either implement
Serialize
myself,but this gets tiring if the struct is too large and is prone to errors, or create
another struct with the field I want just before serializing.
I hereby propose creating a new container attribute
field
that allows forthe creation of fields on the go at the moment of serialization:
So a
CustomFields { a: 10 }
results in:I'm still not happy with the attributes' names, it may make more sense to
call it
serialize_field
or something along those lines?