use crate::error;
use crate::identity;
use crate::error::Context;
pub trait Trait<DataType, FormatType> {
fn context() -> error::Context;
}
pub trait FieldTrait<DataType, FormatType> {
fn context_field(field_name_ref: &str) -> crate::error::Context;
}
pub trait VariantTrait<DataType, FormatType> {
fn context_variant(variant_name_ref: &str) -> crate::error::Context;
}
pub trait VariantFieldTrait<DataType, FormatType> {
fn context_variant_field(variant_name_ref: &str, field_name_ref: &str) -> crate::error::Context;
}
impl<DataType, DeserializerType, FormatType> Trait<DataType, FormatType> for DeserializerType
where FormatType: crate::format::Trait,
DeserializerType: crate::deserializer::identity::Trait<DataType, FormatType> {
fn context() -> error::Context {
error::Context {
trace: <Self as crate::deserializer::identity::Trait<DataType, FormatType>>::data_definition(),
}
}
}
impl<DataType, DeserializerType, FormatType> FieldTrait<DataType, FormatType> for DeserializerType
where FormatType: crate::format::Trait,
DeserializerType: crate::deserializer::identity::Trait<DataType, FormatType> {
fn context_field(field_name_ref: &str) -> Context {
error::Context {
trace: std::string::String::from(format!("{}[{}]",
DeserializerType::data_definition(),
field_name_ref,
))
}
}
}
impl<DataType, DeserializerType, FormatType> VariantTrait<DataType, FormatType> for DeserializerType
where FormatType: crate::format::Trait,
DeserializerType: crate::deserializer::identity::Trait<DataType, FormatType> {
fn context_variant(variant_name_ref: &str) -> Context {
error::Context {
trace: std::string::String::from(format!("{}::{}",
DeserializerType::data_definition(),
variant_name_ref,
))
}
}
}
impl<DataType, DeserializerType, FormatType> VariantFieldTrait<DataType, FormatType> for DeserializerType
where FormatType: crate::format::Trait,
DeserializerType: crate::deserializer::identity::Trait<DataType, FormatType> {
fn context_variant_field(variant_name_ref: &str, field_name_ref: &str) -> Context {
error::Context {
trace: std::string::String::from(format!("{}::{}[{}]",
DeserializerType::data_definition(),
variant_name_ref,
field_name_ref,
))
}
}
}