How to deserialize back into a correct format

I’ve seen some examples and explanations on the net and I understand what the problem is but I don’t now how to solve it … Lets start with the problem :

--> src/crates/tlb/src/
151 |     pub fn read<'de, T: Deserialize<'de>>(&mut self, data: String)-> T {
    |                   --- lifetime `'de` defined here
152 |         
153 |         bincode::deserialize(&(self.obj.translate(data).unwrap())).unwrap()
    |         ----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
    |         |                     |
    |         |                     creates a temporary which is freed while still in use
    |         argument requires that borrow lasts for `'de`
154 | 
155 |     }
    |     - temporary value is freed at the end of this statement

What is happening : translate() method of obj takes in a String, processes it and returns Result<Vec<u8>, Err> Sometimes I want to deserialize its return back to String sometimes I need it in Vec<u8> format. my question: What I need to do to make one function return two forms of a result. Or at leas A string for starters :slight_smile:

Thank you

Change the bound on T to T: for<'de> Deserialize<'de> or use the serde::de::DeserializeOwned trait.

What do I need to eat to be smart like you guys ?


1 Like

You need to eat experience :wink:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.