use crate::data::DamlResult;
use crate::data::value::DamlValue;
use crate::nat::Nat;
use crate::primitive_types::{
DamlBool, DamlContractId, DamlDate, DamlFixedNumeric, DamlGenMap, DamlInt64, DamlParty, DamlText, DamlTextMap,
DamlTimestamp, DamlUnit,
};
pub trait DamlSerializableType: Sized {}
impl DamlSerializableType for DamlUnit {}
impl DamlSerializableType for DamlBool {}
impl DamlSerializableType for DamlInt64 {}
impl DamlSerializableType for DamlText {}
impl DamlSerializableType for DamlParty {}
impl DamlSerializableType for DamlContractId {}
impl DamlSerializableType for DamlTimestamp {}
impl DamlSerializableType for DamlDate {}
impl<T> DamlSerializableType for DamlFixedNumeric<T> where T: DamlSerializableType + Nat {}
impl<T> DamlSerializableType for Box<T> where T: DamlSerializeInto<DamlValue> + DamlSerializableType {}
impl<T> DamlSerializableType for Option<T> where T: DamlSerializeInto<DamlValue> + DamlSerializableType {}
impl<T> DamlSerializableType for Vec<T> where T: DamlSerializeInto<DamlValue> + DamlSerializableType {}
impl<K, V> DamlSerializableType for DamlGenMap<K, V>
where
K: DamlSerializeInto<DamlValue> + DamlSerializableType,
V: DamlSerializeInto<DamlValue> + DamlSerializableType,
{
}
impl<V> DamlSerializableType for DamlTextMap<V> where V: DamlSerializeInto<DamlValue> + DamlSerializableType {}
pub trait DamlSerializeFrom<T>: Sized
where
T: DamlSerializableType,
{
fn serialize_from(_: T) -> Self;
}
pub trait DamlSerializeInto<T = DamlValue>: DamlSerializableType {
fn serialize_into(self) -> T;
}
impl<T, U> DamlSerializeInto<U> for T
where
T: DamlSerializableType,
U: DamlSerializeFrom<T>,
{
fn serialize_into(self) -> U {
U::serialize_from(self)
}
}
pub trait DamlDeserializeFrom: DamlDeserializableType {
fn deserialize_from(value: DamlValue) -> DamlResult<Self>;
}
pub trait DamlDeserializeInto<T: DamlDeserializableType> {
fn deserialize_into(self) -> DamlResult<T>;
}
impl<T> DamlDeserializeInto<T> for DamlValue
where
T: DamlDeserializeFrom,
{
fn deserialize_into(self) -> DamlResult<T> {
T::deserialize_from(self)
}
}
pub trait DamlDeserializableType: Sized {}
impl DamlDeserializableType for DamlUnit {}
impl DamlDeserializableType for DamlBool {}
impl DamlDeserializableType for DamlInt64 {}
impl DamlDeserializableType for DamlText {}
impl DamlDeserializableType for DamlParty {}
impl DamlDeserializableType for DamlContractId {}
impl DamlDeserializableType for DamlTimestamp {}
impl DamlDeserializableType for DamlDate {}
impl<T> DamlDeserializableType for DamlFixedNumeric<T> where T: DamlDeserializableType + Nat {}
impl<T> DamlDeserializableType for Box<T> where T: DamlDeserializeFrom + DamlDeserializableType {}
impl<T> DamlDeserializableType for Option<T> where T: DamlDeserializeFrom + DamlDeserializableType {}
impl<T> DamlDeserializableType for Vec<T> where T: DamlDeserializeFrom + DamlDeserializableType {}
impl<K, V> DamlDeserializableType for DamlGenMap<K, V>
where
K: DamlDeserializeFrom + DamlDeserializableType,
V: DamlDeserializeFrom + DamlDeserializableType,
{
}
impl<V> DamlDeserializableType for DamlTextMap<V> where V: DamlDeserializeFrom + DamlDeserializableType {}