expression
Borrowed text from binary payload
A compatible borrowed field can refer to the source buffer rather than owning a new String. Keep the buffer alive for the result; not every data representation supports borrowing. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): pear Common mistake: Returning a reference to bytes owned only inside a helper function.
Formal Syntax & Structure
rust syntaxrust
postcard::from_bytes::<&str>(bytes)Working Example
Example Snippetrust
fn main() { let bytes = postcard::to_allocvec(&"pear").unwrap(); let text: &str = postcard::from_bytes(&bytes).unwrap(); println!("{}", text);}