Skip to main content

from_str_into

Function from_str_into 

Source
pub fn from_str_into<'facet>(
    input: &str,
    partial: Partial<'facet, false>,
) -> Result<Partial<'facet, false>, DeserializeError>
Expand description

Deserialize JSON from a string 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_str_into;
use facet_reflect::Partial;

#[derive(Facet, Debug, PartialEq)]
struct Person {
    name: String,
    age: u32,
}

let json = r#"{"name": "Alice", "age": 30}"#;
let partial = Partial::alloc_owned::<Person>().unwrap();
let partial = from_str_into(json, partial).unwrap();
let value = partial.build().unwrap();
let person: Person = value.materialize().unwrap();
assert_eq!(person.name, "Alice");
assert_eq!(person.age, 30);