use sonic_rs::Error as SonicError;
pub trait ExportedSerialize {
fn to_json(&self) -> Result<String, SonicError>;
}
pub trait ExportedDeserialize: Sized {
fn from_json(json: &str) -> Result<Self, SonicError>;
}
impl<T> ExportedSerialize for T
where
T: serde::Serialize,
{
fn to_json(&self) -> Result<String, SonicError> {
sonic_rs::to_string(self)
}
}
impl<T> ExportedDeserialize for T
where
T: for<'de> serde::Deserialize<'de>,
{
fn from_json(json: &str) -> Result<Self, SonicError> {
sonic_rs::from_str(json)
}
}