pub fn from_slice<T>(input: &[u8]) -> Result<T, DeserializeError<JsonError>>where
T: Facet<'static>,Expand description
Deserialize a value from JSON 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 fields cannot be deserialized with this function;
use String or Cow<str> instead. For zero-copy deserialization into
borrowed types, use from_slice_borrowed.
ยงExample
use facet::Facet;
use facet_json::from_slice;
#[derive(Facet, Debug, PartialEq)]
struct Point {
x: i32,
y: i32,
}
let json = br#"{"x": 10, "y": 20}"#;
let point: Point = from_slice(json).unwrap();
assert_eq!(point.x, 10);
assert_eq!(point.y, 20);