Feat/allow generic v to be arbitrary struct #1079
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.
Hey everyone!
Currently I am finding myself having to deserialize a JSON that might have N number of arbitrarily named properties. It is +/- as follows:
Where in this case I wrote only two objects for brevity's sake. In this scenario I have not a list of objects, but a outer object with unknown size.
And each object follows a specific contract (data structure), though some properties might be optional. Considering this, I wanted to define my data structs as follows:
But this way, in the current `master` branch, pointing to commit `39f5ad1`, I get the errors inside this spoiler dropdown:
By looking at the
Map<K, V>
definition I see that every implementation of this generic struct considers the specific case whereMap<String, Value>
. So it does not care if a given user struct implements theDeserialize
trait.On the other hand, I believe every serde user should not implement a custom map to make it work with a custom object/struct that implements the
Deserialize
trait. For two main reasons:Map<K, V>
;V
generic, instead of hard-coding it to always beValue
;Map<K, V>
to accept any givenV
that implementsSerialize
andDeserialize
.Considering this I am bringing this PR where I generalized all the
Map<K, V>
implementations. Here are the unit test that I ran with this implementation:For facilitate the reviewers life, here are the dependency pointing to the implementation, or current
master
on my fork:All tests passed