Function rudano::from_str

source ·
pub fn from_str<'a, T: Deserialize<'a>>(s: &'a str) -> Result<T>
Expand description

Deserializes the given str as a value of type T.

Example

use serde::Deserialize;

#[derive(Deserialize)]
struct MyStruct {
    number: i32,
    string: String,
}

let string = r#"MyStruct {
    number: 69,
    string: "nice",
}"#;
let value: MyStruct = rudano::from_str(string).unwrap();

let expected = MyStruct {
    number: 69,
    string: "nice".to_string(),
};

assert_eq!(value, expected);

Errors

Deserialization can fail if T’s Deserialize fail, the input is invalid Rudano or the data layout doesn’t match.