pub fn from_slice<T>(input: &[u8]) -> Result<T, DeserializeError<PostcardError>>where
T: Facet<'static>,Expand description
Deserialize a value from postcard bytes into an owned type.
This is the recommended default for most use cases. The input does not need to outlive the result, making it suitable for deserializing from temporary buffers (e.g., HTTP request bodies).
Types containing &str or &[u8] fields cannot be deserialized with this
function; use String/Vec<u8> or Cow<str>/Cow<[u8]> instead. For
zero-copy deserialization into borrowed types, use from_slice_borrowed.
ยงExample
use facet::Facet;
use facet_postcard::from_slice;
#[derive(Facet, Debug, PartialEq)]
struct Point {
x: i32,
y: i32,
}
// Postcard encoding: [x=10 (zigzag), y=20 (zigzag)]
let bytes = &[0x14, 0x28];
let point: Point = from_slice(bytes).unwrap();
assert_eq!(point.x, 10);
assert_eq!(point.y, 20);