Skip to content
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

deserialize_in_place equivalent for bincode 2.0 #675

Open
jrose-signal opened this issue Oct 23, 2023 · 1 comment
Open

deserialize_in_place equivalent for bincode 2.0 #675

jrose-signal opened this issue Oct 23, 2023 · 1 comment

Comments

@jrose-signal
Copy link

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.

@VictorKoenders
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants