pub trait Adapter: Sized {
type Value;
type Error;
// Required methods
fn serialize_value<T: Serialize + ?Sized>(
value: &T,
) -> Result<Self::Value, Self::Error>;
fn apply_mutation(
old_value: &mut Self::Value,
mutation: Mutation<Self>,
path_stack: &mut Path<false>,
) -> Result<(), MutationError>;
fn merge_append(
old_value: &mut Self::Value,
append_value: Self::Value,
path_stack: &mut Path<false>,
) -> Result<(), MutationError>;
fn get_len(
value: &Self::Value,
path_stack: &mut Path<false>,
) -> Result<usize, MutationError>;
}Expand description
Trait for adapting mutations to different serialization formats.
The Adapter trait provides an abstraction layer between the mutation detection system and the
serialization format. This allows morphix to support multiple output formats while maintaining
type safety.
§Type Parameters
Replace: The type used to represent replacement valuesAppend: The type used to represent append valuesError: The error type returned by serialization / deserialization operations
§Example
use morphix::Adapter;
use serde::Serialize;
use serde_json::value::Serializer;
use serde_json::{Error, Value};
struct JsonAdapter;
impl Adapter for JsonAdapter {
type Value = Value;
type Error = Error;
fn serialize_value<T: Serialize + ?Sized>(value: &T) -> Result<Self::Value, Self::Error> {
value.serialize(Serializer)
}
// ... other methods
}Required Associated Types§
Required Methods§
Sourcefn serialize_value<T: Serialize + ?Sized>(
value: &T,
) -> Result<Self::Value, Self::Error>
fn serialize_value<T: Serialize + ?Sized>( value: &T, ) -> Result<Self::Value, Self::Error>
Serializes a value into the adapter’s Value type.
Sourcefn apply_mutation(
old_value: &mut Self::Value,
mutation: Mutation<Self>,
path_stack: &mut Path<false>,
) -> Result<(), MutationError>
fn apply_mutation( old_value: &mut Self::Value, mutation: Mutation<Self>, path_stack: &mut Path<false>, ) -> Result<(), MutationError>
Applies a Mutation to an existing value.
Sourcefn merge_append(
old_value: &mut Self::Value,
append_value: Self::Value,
path_stack: &mut Path<false>,
) -> Result<(), MutationError>
fn merge_append( old_value: &mut Self::Value, append_value: Self::Value, path_stack: &mut Path<false>, ) -> Result<(), MutationError>
Merges one append value into another.
fn get_len( value: &Self::Value, path_stack: &mut Path<false>, ) -> Result<usize, MutationError>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.