from_str

Function from_str 

Source
pub fn from_str<T>(input: &str) -> Result<T, DeserializeError<JsonError>>
where T: Facet<'static>,
Expand description

Deserialize a value from a JSON string 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_str_borrowed.

ยงExample

use facet::Facet;
use facet_json::from_str;

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

let json = r#"{"name": "Alice", "age": 30}"#;
let person: Person = from_str(json).unwrap();
assert_eq!(person.name, "Alice");
assert_eq!(person.age, 30);