Struct as map representation and leftover field collection #1178
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 PR is similar to #1177 in spirit but very different in implementation. Because of current restrictions that
serialize_field
on the struct visitor requires static strings and because there is a hint about the incoming field names on the struct visitor I think this "collect other things" feature currently only really works when serializing as maps.I tried a different approach now which also adds a neat additional feature. A (struct) container can now be marked with
#[serde(repr="map")]
which serializes the struct not as a struct but as a map. This then also unlocks#[serde(unknown_fields_into="...")]
So the example looks slightly modified like this:
Unlike the other one this however has a chance of being merged I think because it can be made sound and user friendly without requiring changes to the already existing traits. In a far serde 2.0 future the
repr="map"
requirement could then be removed.Known issues:
to_string
which does not work inno_std
. Generally this right now does not work inno_std
mode. That might be okay if it's shimmed properly.__value
decoding is complex. Could need some refactoring