-
Notifications
You must be signed in to change notification settings - Fork 245
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
fix: workaround for WithOtherFields
#495
Conversation
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.
smol nit
I consider this a tmp workaround, there's probably a better solution for this problem but for now this is sufficient
crates/rpc-types/src/with_other.rs
Outdated
let inner_keys = match &inner_serialzed { | ||
Value::Object(map) => map.keys().collect::<Vec<_>>(), | ||
_ => Vec::new(), | ||
}; | ||
|
||
for key in inner_keys { | ||
helper.other.remove(key); | ||
} |
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.
we can move the for loop into the match arm and avoid the vec alloc I believe
* fix: avoid duplicating fields in WithOtherFields * add test * avoid alloc * fmt * chore: add note --------- Co-authored-by: Matthias Seitz <[email protected]>
* fix: avoid duplicating fields in WithOtherFields * add test * avoid alloc * fmt * chore: add note --------- Co-authored-by: Matthias Seitz <[email protected]>
Motivation
Ref serde-rs/serde#1909
ref #493
Currently deserializing
WithOtherFields<T>
whereT
is a struct with multiple levels of fields withserde(flatten)
, the resulted object would have fields of theinner
struct duplicated inother
. Example of this behavior is a deserialization ofAnyTransactionReceipt
:resulted receipt
Solution
This PR implements a workaround which serializes
inner
and removes all duplicating keys after deserializationPR Checklist