Skip to main content

parse

Function parse 

Source
pub fn parse<T>(input: &str) -> Result<Vec<T>>
where T: DeserializeOwned + Send + 'static,
Available on crate feature parallel only.
Expand description

Deserialise every YAML document in input into T, parsing in parallel via Rayon’s global thread pool.

T must be Send because the per-document parses run on arbitrary worker threads. The result is collected back into a Vec<T> in document order.

Reads as noyalib::parallel::parse::<MyType>(input) — concurrency lives in the namespace, the verb is one word.

§Errors

  • Any document fails to parse — the first error is returned; sibling documents may still complete in parallel but their results are discarded.

§Examples

let yaml = "---\nport: 80\n---\nport: 443\n";
#[derive(serde::Deserialize, Debug, PartialEq)]
struct Service { port: u16 }
let v: Vec<Service> = noyalib::parallel::parse(yaml).unwrap();
assert_eq!(v[0].port, 80);
assert_eq!(v[1].port, 443);