deserialize_in_place equivalent for bincode 2.0
jrose-signal opened this issue · comments
Switching from Serde's deserialize
to deserialize_in_place
saves a significant amount of code size for us, due to Result<Self, Error>
requiring a memcpy on success if it's part of a larger structure. It would stink to lose that option if/when we update to bincode 2.0.
Note that #425 claims that
Internally there is no actual
deserialize_in_place
. Serde's implementation is:#[doc(hidden)] fn deserialize_in_place<D>(deserializer: D, place: &mut Self) -> Result<(), D::Error> where D: Deserializer<'de>, { // Default implementation just delegates to `deserialize` impl. *place = Deserialize::deserialize(deserializer)?; Ok(()) }so for bincode 2 we're considering not supporting this (or implementing it properly)
However, that's merely the default implementation, and serde_derive
has a feature to generate proper deserialize_in_place
implementations.
If someone wants to write a PR with this, we can merge that. I've never worked with deserialize_in_place
. It would be nice to add a test with serde_derive
doing the proper implementation too.