I have been messing around with deserialization and am trying to get zero-copy deserialization working in my app. Playing around in a small toy main() method I was able to get it working, but when I try to use it in something a bit more real, the compiler yells at me. This is what my deserialize function looks like:
pub fn deserialize<'de, T>(buff: &'de [u8]) -> T
where
T: Deserialize<'de> + DeserializeOwned,
{
let mut de = Deserializer::from_read_ref(buff);
Deserialize::deserialize(&mut de).expect("Unable to deserialize!")
}
And this is the function that calls it (slimmed down)
pub async fn get<'de, T>(&mut self, key: String) -> T
where
T: Deserialize<'de>,
{
.
.
.
let buff = receiver.await.expect("Receiver Error!").payload;
deserialize(&buff)
}
I thought that the buffer was living long enough, but the compiler says that it is being dropped at the closing bracket while still being borrowed. Does it have something to do with my function being async?