pub fn from_slice<T>(input: &[u8]) -> Result<T, DeserializeError<MsgPackError>>where
T: Facet<'static>,Expand description
Deserialize a value from MsgPack 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_msgpack::from_slice;
#[derive(Facet, Debug, PartialEq)]
struct Point {
x: i32,
y: i32,
}
// MsgPack encoding of {"x": 10, "y": 20}
let bytes = &[0x82, 0xa1, b'x', 0x0a, 0xa1, b'y', 0x14];
let point: Point = from_slice(bytes).unwrap();
assert_eq!(point.x, 10);
assert_eq!(point.y, 20);