from_str

Function from_str 

Source
pub fn from_str<'de, T>(string: &'de str) -> Result<T>
where T: Deserialize<'de>,
Expand description

Deserialize an instance of type T from a string of MASON text.

§Example

use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct User {
    fingerprint: String,
    location: String,
}

// The type of `j` is `&str`
let j = "
    fingerprint: \"0xF9BA143B95FF6D82\"
    location: \"Menlo Park, CA\"
";

let u: User = mason_rs::from_str(j).unwrap();
println!("{:#?}", u);

§Errors

This conversion can fail if the structure of the input does not match the structure expected by T, for example if T is a struct type but the input contains something other than a MASON map. It can also fail if the structure is correct but T’s implementation of Deserialize decides that something is wrong with the data, for example required struct fields are missing from the MASON map or some number is too big to fit in the expected primitive type.