use std::fmt::Debug;
use serde::{Deserialize, Serialize};
pub trait Value: Sized {
type Error: Debug + serde::de::Error + serde::ser::Error;
fn from_typed<V: Serialize>(value: &V) -> Result<Self, Self::Error>;
fn to_typed<'a, T: Deserialize<'a>>(&'a self) -> Result<T, Self::Error>;
}
#[cfg(feature = "json")]
impl Value for serde_json::Value {
type Error = serde_json::Error;
fn from_typed<V: Serialize>(value: &V) -> Result<Self, Self::Error> {
serde_json::to_value(value)
}
fn to_typed<'a, T: Deserialize<'a>>(&'a self) -> Result<T, Self::Error> {
T::deserialize(self)
}
}
#[cfg(feature = "cbor")]
impl Value for serde_cbor::Value {
type Error = serde_cbor::Error;
fn from_typed<V: Serialize>(value: &V) -> Result<Self, Self::Error> {
serde_cbor::value::to_value(value)
}
fn to_typed<'a, T: Deserialize<'a>>(&'a self) -> Result<T, Self::Error> {
todo!()
}
}