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 Vec<Cow<'static, str>>,
) -> Result<(), MutationError>;
fn merge_append(
old_value: &mut Self::Value,
new_value: Self::Value,
path_stack: &mut Vec<Cow<'static, str>>,
) -> Result<(), 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.
§Arguments
value- value to be serialized as a replacement
Sourcefn apply_mutation(
old_value: &mut Self::Value,
mutation: Mutation<Self>,
path_stack: &mut Vec<Cow<'static, str>>,
) -> Result<(), MutationError>
fn apply_mutation( old_value: &mut Self::Value, mutation: Mutation<Self>, path_stack: &mut Vec<Cow<'static, str>>, ) -> Result<(), MutationError>
Applies a Mutation to an existing value.
§Arguments
old_value- value to be modifiedmutation- mutation to applypath_stack- stack for tracking the current path (used for error reporting)
§Errors
- Returns
MutationError::IndexErrorif the path doesn’t exist. - Returns
MutationError::OperationErrorif the operation cannot be performed.
Sourcefn merge_append(
old_value: &mut Self::Value,
new_value: Self::Value,
path_stack: &mut Vec<Cow<'static, str>>,
) -> Result<(), MutationError>
fn merge_append( old_value: &mut Self::Value, new_value: Self::Value, path_stack: &mut Vec<Cow<'static, str>>, ) -> Result<(), 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.