1#[cfg(test)]
3mod test;
4
5use crate::ast::RapidRecastDefinition;
6use crate::{ParseRRDL, SaveRRDL};
7use std::io::Cursor;
8
9pub struct JsonRRDL {}
11
12impl<'self_life, 'input_life> ParseRRDL<'self_life, 'input_life> for JsonRRDL {
13 fn parse_rrdl(
14 &'self_life self,
15 input: &'input_life str,
16 ) -> Result<RapidRecastDefinition<'input_life>, String> {
17 serde_json::from_str(input).map_err(|e| format!("Failed at le serde json lol: {}", e))
18 }
19}
20
21impl SaveRRDL<Cursor<Vec<u8>>> for JsonRRDL {
22 fn save_rrdl<'param>(
23 &'param self,
24 definition: &'param RapidRecastDefinition,
25 ) -> Cursor<Vec<u8>> {
26 let res = serde_json::to_vec(definition).unwrap();
27 Cursor::new(res)
28 }
29}