kurobako_core/
json.rs

1//! JSON.
2use crate::{Error, Result};
3use serde::Deserialize;
4use std::io::Read;
5
6/// JSON representation of a recipe.
7pub type JsonRecipe = serde_json::Value;
8
9/// Parses the given JSON string.
10pub fn parse_json<T>(json: &str) -> Result<T>
11where
12    T: for<'a> Deserialize<'a>,
13{
14    let v = track!(serde_json::from_str(json).map_err(Error::from))?;
15    Ok(v)
16}
17
18/// Loads entries from the given reader.
19pub fn load<R, T>(reader: R) -> Result<Vec<T>>
20where
21    R: Read,
22    T: for<'a> Deserialize<'a>,
23{
24    serde_json::Deserializer::from_reader(reader)
25        .into_iter()
26        .map(|json| track!(json.map_err(Error::from)))
27        .collect()
28}