jamesmunns / postcard

A no_std + serde compatible message library for Rust
Apache License 2.0
930 stars 89 forks source link

Remove unnecessary lifetime from CRC digest in deserializer #155

Closed MathiasKoch closed 6 months ago

MathiasKoch commented 6 months ago

This PR is the deserialize complement to https://github.com/jamesmunns/postcard/pull/129

This is required to allow wrappers such as

fn deserialize(buf: &[u8]) -> Result<Data<'_>, Error> {
    let crc = Crc::<u32>::new(&CRC_32_ISCSI);
    let digest = crc.digest();
    postcard::from_bytes_crc32(buf, digest).map_err(|_| Error::Deserialize)
}

without getting

   |
54 |         let digest = crc.digest();
   |                      --- `crc` is borrowed here
55 |         postcard::from_bytes_crc32(buf, digest).map_err(|_| Error::Deserialize)
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function
netlify[bot] commented 6 months ago

Deploy Preview for cute-starship-2d9c9b canceled.

Name Link
Latest commit d761d65f015b83d569122475eafaca6737ab4fe0
Latest deploy log https://app.netlify.com/sites/cute-starship-2d9c9b/deploys/6644fcef2a6dd2000801a98f
MathiasKoch commented 6 months ago

Nevermind this.. Moved a bit too fast with the PR.. Don't think this will work in practice?