Skip to main content

load_all_as

Function load_all_as 

Source
pub fn load_all_as<T>(input: &str) -> Result<Vec<T>>
where T: for<'de> Deserialize<'de> + 'static,
Expand description

Load all YAML documents and deserialize them into a typed vector.

§Examples

use noyalib::document::load_all_as;
use serde::Deserialize;

#[derive(Debug, Deserialize, PartialEq)]
struct Doc {
    name: String,
}

let yaml = "---
name: first
---
name: second
";

let docs: Vec<Doc> = load_all_as(yaml).unwrap();
assert_eq!(docs.len(), 2);
assert_eq!(docs[0].name, "first");
assert_eq!(docs[1].name, "second");

§Errors

Returns an error if parsing fails or if any document cannot be deserialized into the target type.