Skip to main content

from_slice_into

Function from_slice_into 

Source
pub fn from_slice_into<'facet>(
    input: &[u8],
    partial: Partial<'facet, false>,
) -> Result<Partial<'facet, false>, DeserializeError>
Expand description

Deserialize JSON from bytes into an existing Partial.

This is useful for reflection-based deserialization where you don’t have a concrete type T at compile time, only its Shape metadata. The Partial must already be allocated for the target type.

This version produces owned strings (no borrowing from input).

§Example

use facet::Facet;
use facet_json::from_slice_into;
use facet_reflect::Partial;

#[derive(Facet, Debug, PartialEq)]
struct Point {
    x: i32,
    y: i32,
}

let json = br#"{"x": 10, "y": 20}"#;
let partial = Partial::alloc_owned::<Point>().unwrap();
let partial = from_slice_into(json, partial).unwrap();
let value = partial.build().unwrap();
let point: Point = value.materialize().unwrap();
assert_eq!(point.x, 10);
assert_eq!(point.y, 20);