-
-
Notifications
You must be signed in to change notification settings - Fork 872
Open
Description
The Deserialize implementation of a type with a field annotated #[serde(flatten)] currently buffers up all of the unknown map entries in memory, and then deserializes the flattened value from them at the end. This approach has a couple of downsides:
- It causes the deserializer to allocate when that would normally not be the case.
- It confuses "smart" deserializers - things like serde_ignored_value or serde_json's error position tracking don't work properly.
- It can lose out on special casing in deserializers based on hinting.
Fortunately, there's alternate approach that avoids all of these issues! Instead of buffering, we can create a custom MapAccess which intercepts fields that we want to handle in the top-level type, and then returning the remainder to the nested deserialize implementation: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=96546d7ba882b70042268a0b48de6286
Virgiel and dtheodor
Metadata
Metadata
Assignees
Labels
No labels