pub fn from_str<D>(doc: &str) -> Result<Vec<D>, SerdeError> where
D: DeserializeOwned,
This is supported on crate feature
serde
only.Expand description
Parse the document and deserialize nodes to a specific type.
Since the document can be split into multiple parts, so this function will return a vector container.
use serde::Deserialize;
use yaml_peg::serialize::from_str;
#[derive(Deserialize)]
struct Member {
name: String,
married: bool,
age: u8,
}
let doc = "
---
name: Bob
married: true
age: 46
";
// Return Vec<Member>, use `.remove(0)` to get the first one
let officer = from_str::<Member>(doc).unwrap().remove(0);
assert_eq!("Bob", officer.name);
assert!(officer.married);
assert_eq!(46, officer.age);