pub trait Adapter: Sized {
type Value;
type Error;
// Required methods
fn from_mutation(mutation: Mutations<Self::Value>) -> Self;
fn serialize_value<T: Serialize + ?Sized>(
value: &T,
) -> Result<Self::Value, Self::Error>;
fn get_mut<'a>(
value: &'a mut Self::Value,
segment: &PathSegment,
allow_create: bool,
) -> Option<&'a mut Self::Value>;
fn delete(
value: &mut Self::Value,
segment: &PathSegment,
) -> Option<Self::Value>;
fn append(
value: &mut Self::Value,
append_value: Self::Value,
) -> Option<usize>;
fn len(value: &Self::Value) -> Option<usize>;
fn truncate(value: &mut Self::Value, truncate_len: usize) -> Option<usize>;
// Provided method
fn mutate(
value: &mut Self::Value,
mutation: Mutation<Self::Value>,
path_stack: &mut Path<false>,
) -> Result<(), MutationError> { ... }
}Expand description
Required Associated Types§
Required Methods§
Sourcefn from_mutation(mutation: Mutations<Self::Value>) -> Self
fn from_mutation(mutation: Mutations<Self::Value>) -> Self
Constructs the adapter from an optional mutation.
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 get_mut<'a>(
value: &'a mut Self::Value,
segment: &PathSegment,
allow_create: bool,
) -> Option<&'a mut Self::Value>
fn get_mut<'a>( value: &'a mut Self::Value, segment: &PathSegment, allow_create: bool, ) -> Option<&'a mut Self::Value>
Gets a mutable reference to a nested value by path segment.
This method navigates into value using the provided segment and returns a mutable
reference to the nested value if it exists.
§Parameters
value: The value to navigate intosegment: The path segment indicating which nested value to accessallow_create: Iftrueand the segment refers to a non-existent key in an object / map, an empty value will be created at that location
§Returns
Some(value): A mutable reference to the nested valueNone: If the operation is not supported on this value type, or if the segment refers to a non-existent location andallow_createisfalse
Sourcefn delete(value: &mut Self::Value, segment: &PathSegment) -> Option<Self::Value>
Available on crate feature delete only.
fn delete(value: &mut Self::Value, segment: &PathSegment) -> Option<Self::Value>
delete only.Removes a value at the specified path segment.
This method removes and returns the value at the location specified by segment
within value. It is used to apply Delete mutations.
§Parameters
value: The parent value containing the element to removesegment: The path segment indicating which nested value to remove
§Returns
Some(removed_value): The removed value if the operation succeededNone: If the operation is not supported on this value type (e.g., not a map), or if the segment refers to a non-existent location
Sourcefn append(value: &mut Self::Value, append_value: Self::Value) -> Option<usize>
Available on crate feature append only.
fn append(value: &mut Self::Value, append_value: Self::Value) -> Option<usize>
append only.Appends a value to the end of another value.
This method performs an append operation similar to String::push_str or
Extend::extend, merging append_value into the end of value.
§Parameters
value: The value to append toappend_value: The value to be appended
§Returns
Some(append_len): The length of the appended portionNone: If the operation is not supported (e.g., incompatible types betweenvalueandappend_value, orvalueis not an appendable type)
§Note
For strings, the returned length represents the char count, not the byte length.
Sourcefn len(value: &Self::Value) -> Option<usize>
Available on crate feature append only.
fn len(value: &Self::Value) -> Option<usize>
append only.Returns the appendable length of a value.
This method returns the current length of a value that can be used with
append operations.
§Returns
Some(len): The current length of the valueNone: If the value is not an appendable type
§Note
For strings, the returned length represents the char count, not the byte length.
Sourcefn truncate(value: &mut Self::Value, truncate_len: usize) -> Option<usize>
Available on crate feature truncate only.
fn truncate(value: &mut Self::Value, truncate_len: usize) -> Option<usize>
truncate only.Truncates a value by removing elements from the end.
This method removes up to truncate_len elements from the end of value.
§Parameters
value: The value to truncatetruncate_len: The number of elements to remove from the end
§Returns
Some(remaining): The remaining truncation length that could not be applied. Returns0if the full truncation was successful. Iftruncate_lenexceeds the actual length, returnstruncate_len - actual_lenand clears the value.None: If the operation is not supported on this value type
§Note
For strings, the returned length represents the char count, not the byte length.
Provided Methods§
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.