Adapter

Trait Adapter 

Source
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 values
  • Append: The type used to represent append values
  • Error: 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§

Source

type Value

Type used to represent Replace and Append values.

Source

type Error

Error type for serialization / deserialization operations.

Required Methods§

Source

fn serialize_value<T: Serialize + ?Sized>( value: &T, ) -> Result<Self::Value, Self::Error>

Serializes a value into the adapter’s Value type.

Source

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.

Source

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.

Source

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.

Implementors§