pub fn decode<T: Deserialize>(bytes: &[u8]) -> Result<T>Expand description
Decode a value of type T from bytes, requiring the input to be fully
consumed.
This is the Tier-1 entry point — the one-line surface for the common
case. After the value has been read, the decoder checks that no bytes
remain; trailing input is reported as SerialError::TrailingBytes.
Callers that want to read several values from a single buffer should use
Decoder directly.
§Examples
let bytes = pack_io::encode(&"hello").unwrap();
let back: String = pack_io::decode(&bytes).unwrap();
assert_eq!(back, "hello");§Errors
- Returns
SerialError::TrailingByteswhen extra bytes follow the value. - Propagates any
SerialErrorfrom the type’sDeserializeimpl.