cataclysm/session/json_session_parser.rs
1use super::{SessionParser};
2use crate::Error;
3use serde::{Serialize, de::{DeserializeOwned}};
4
5/// Json implementation of a [SessionParser].
6pub struct JsonSessionParser;
7
8impl <T: Serialize + DeserializeOwned> SessionParser<T> for JsonSessionParser {
9 fn from_str(source: String) -> Result<T, Error> {
10 Ok(serde_json::from_str(&source)?)
11 }
12
13 fn to_string(source: T) -> Result<String, Error> {
14 Ok(serde_json::to_string(&source)?)
15 }
16}