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

How to use this crate without use of struct fields #34

Open
kylecarow opened this issue Aug 18, 2022 · 0 comments
Open

How to use this crate without use of struct fields #34

kylecarow opened this issue Aug 18, 2022 · 0 comments

Comments

@kylecarow
Copy link

I'm relatively new to Rust so bear with me. I'm working on a project that provides a Python API to Rust code via Pyo3. In my project I'm trying to enable fast serialization and deserialization using bincode. I read this crate can mitigate the performance issues I'm seeing (bincode takes 3 times longer than serialization/deserialization with serde_json).

It's not clear to me how to take advantage of this crate when I don't use a struct field to hold the data.

For reference, this is what the unedited, actual serialization and deserialization code snippet looks like, with the Pyo3 API intact:

pub fn to_bincode(&self) -> PyResult<Vec<u8>> {
    Ok(serialize(&self).unwrap())
}
#[classmethod]
pub fn from_bincode(_cls: &PyType, encoded: Vec<u8>) -> PyResult<Self> {
    Ok(deserialize(&encoded).unwrap())
}

With the API removed, I suppose would be the analogous code:

pub fn to_bincode(&self) -> Vec<u8> {
    serialize(&self).unwrap()
}
pub fn from_bincode(encoded: Vec<u8>) -> Self {
    deserialize(&encoded).unwrap()
}

See also: PyO3/pyo3#100

How can I utilize this crate in this case?

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

No branches or pull requests

1 participant