Skip to main content

from_value

Function from_value 

Source
pub fn from_value<T>(value: &Value) -> Result<T>
where T: for<'de> Deserialize<'de> + 'static,
Expand description

Deserialize a Value into a typed T via Serde’s data model.

Useful for second-pass conversion when the first pass parsed into the dynamic Value tree and a typed view is now needed for a sub-tree.

§Errors

  • Error::Deserialize — value does not match T’s shape.
  • Error::Custom — surfaces upstream serde_core::de::Error conversions that don’t fit the structured variants.

§Examples

use noyalib::{from_value, Value};
let v = Value::from(42_i64);
let n: i32 = from_value(&v).unwrap();
assert_eq!(n, 42);