expression

Postcard truncated input

Incomplete encoded records must be rejected rather than filled with guessed defaults. A two-byte tuple cannot be recovered from one byte in this example. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): true true Common mistake: Continuing with partially decoded data after an error.

Formal Syntax & Structure

rust syntaxrust
postcard::from_bytes::<T>(bytes)

Working Example

Example Snippetrust
fn main() {    let bytes = postcard::to_allocvec(&(3u8, 8u8)).unwrap();    println!("{}", postcard::from_bytes::<(u8, u8)>(&bytes).is_ok());    println!("{}", postcard::from_bytes::<(u8, u8)>(&bytes[..1]).is_err());}
Rust Reference