-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
de: Make flattened structs and aliases interact correctly. #1519
Conversation
r? @dtolnay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Would it be sufficient to pass the aliases in the fields given to deserialize_struct instead? I would prefer to avoid adding new Deserializer methods for this.
That's sort-of a breaking change, plus other |
The issue is that FlatStructAccess has no access to the aliases of the struct it's deserializing. Ideally we'd try to serialize the key rather than checking whether we're going to use it before-hand, then actually take the value out, but that happens to be tricky with the current seed API. So we need to somehow get the aliased names back to FlatStructAccess. Introduce a serialize_struct-like API that takes them in a backwards-compatible way. For parallelism, and since we also support aliases on enum variants, also extend the struct_variant API in a similar way. I'm open to better ways to fix it, but I can't think of any other that isn't a breaking change... Fixes serde-rs#1504.
Ah, I haven't heard of Deserializer impls pre-allocating storage based on deserialize_struct. Do you have an example of a format like that? Ordinarily it would be the other way around; the Deserializer impl is aware how much data is in the input, and the Deserialize impl needs to pre-allocate based on MapAccess::size_hint. |
Blerg, I was misreading code (was reading Serializer impls indeed). But searched for a bit and found bits that would look at best fishy with that change. For example bincode serializes structs as tuples, and takes I haven't dug about whether this would break bincode for sure. I'm happy to dig out a bit. If it's just lying about a too large size hint it may be ok I guess.... |
This is gonna be useful to parse aggregate data. Patch with serde-rs/serde#1519 to work-around / fix serde-rs/serde#1504. That bound is needed due to deserialize_with, it's kind-of unfortunate that it cannot be inferred.
Is there any change to the status of this PR? I just ran into this issue in one of my projects, and it would be nice to have it fixed assuming this implementation covers all bases |
Ran into this while trying to make field name changes in a backward-compatible way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed a different way by #2387.
The issue is that FlatStructAccess has no access to the aliases of the struct
it's deserializing.
Ideally we'd try to serialize the key rather than checking whether we're going
to use it before-hand, then actually take the value out, but that happens to be
tricky with the current seed API.
So we need to somehow get the aliased names back to FlatStructAccess. Introduce
a serialize_struct-like API that takes them in a backwards-compatible way. For
parallelism, and since we also support aliases on enum variants, also extend the
struct_variant API in a similar way. I'm open to better ways to fix it, but I
can't think of any other that isn't a breaking change...
Fixes #1504.