pub struct Mutations<V = Box<dyn Serialize>> { /* private fields */ }Expand description
A collection of mutations collected during observation.
It is the return type for flush and
flat_flush operations.
§Behavior
- If no mutations are pushed,
into_innerreturnsNone. - If exactly one mutation is pushed, it is returned as-is.
- If multiple mutations are pushed, they are wrapped in a
Batch.
The is_replace flag tracks whether this collection represents a
whole-value replace. It is set automatically when constructed from a
Replace mutation, and is used by
flat_flush to propagate replace status
to parent observers for replace collapse.
§Example
use morphix::{Mutation, MutationKind, Mutations};
let mut mutations = Mutations::new();
mutations.insert("a", MutationKind::Replace(42));
mutations.insert("b", MutationKind::Truncate(1));
let result = mutations.into_inner();
assert!(matches!(result, Some(Mutation { kind: MutationKind::Batch(_), .. })));Implementations§
Source§impl<V> Mutations<V>
impl<V> Mutations<V>
Sourcepub fn with_capacity(self, capacity: usize) -> Self
pub fn with_capacity(self, capacity: usize) -> Self
Sourcepub fn with_replace(self, is_replace: bool) -> Self
pub fn with_replace(self, is_replace: bool) -> Self
Sets the is_replace flag on this collection.
This is used by composite observers to propagate replace status through
flat_flush, where the collection may
contain per-field mutations that are a flattened decomposition of a whole-value replace.
Sourcepub fn with_prefix(self, segment: impl Into<PathSegment>) -> Self
pub fn with_prefix(self, segment: impl Into<PathSegment>) -> Self
Prepends a path segment to the contained mutation.
If the collection is empty, this is a no-op. Otherwise, the segment is pushed onto the mutation’s reverse-order path.
Sourcepub fn into_inner(self) -> Option<Mutation<V>>
pub fn into_inner(self) -> Option<Mutation<V>>
Consumes the batch and returns the collected mutation.
Sourcepub fn is_replace(&self) -> bool
pub fn is_replace(&self) -> bool
Returns true if this collection represents a whole-value replace.
This flag is set automatically when the collection is created from a
Replace mutation kind, or explicitly via
with_replace. It is used by
flat_flush to signal to the parent
observer that the entire content was replaced, enabling replace collapse.
Sourcepub fn extend(&mut self, mutations: impl Into<Self>)
pub fn extend(&mut self, mutations: impl Into<Self>)
Merges another collection of mutations into this one.
If the incoming collection contains a Batch with an empty path, its
inner mutations are flattened into this collection rather than being nested.
Sourcepub fn insert(
&mut self,
segment: impl Into<PathSegment>,
mutations: impl Into<Self>,
)
pub fn insert( &mut self, segment: impl Into<PathSegment>, mutations: impl Into<Self>, )
Inserts mutations at a specified path segment.
The incoming mutations will have the given segment prepended to their path before being added to this collection.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of top-level mutations in this collection.
A top-level mutation is one with an empty path. If this collection contains a
Batch with an empty path, this returns the number of mutations
in that batch. Otherwise, it returns 1 if a mutation exists, or 0 if the collection is
empty.
Sourcepub fn into_delete(self) -> Self
Available on crate feature delete only.
pub fn into_delete(self) -> Self
delete only.Converts all mutations in this collection to Delete.
Each mutation retains its path but has its kind replaced with
Delete. For a Batch, every inner
mutation is converted individually, preserving the per-field paths. This is used by
flat_flush when the parent needs to emit
deletions for all fields of a flattened struct or map.
Source§impl Mutations
impl Mutations
Sourcepub fn replace_owned<T: Serialize + 'static>(value: T) -> Self
pub fn replace_owned<T: Serialize + 'static>(value: T) -> Self
Sourcepub fn replace<T: Serialize + ?Sized + 'static>(value: &T) -> Self
pub fn replace<T: Serialize + ?Sized + 'static>(value: &T) -> Self
Creates a Mutations containing a single Replace mutation
with the given value.
The value is wrapped in a Box<dyn Serialize> via
[SerializeRef], allowing unsized types like str and [T] to be used.
Sourcepub fn append_owned<T: Serialize + 'static>(value: T) -> Self
Available on crate feature append only.
pub fn append_owned<T: Serialize + 'static>(value: T) -> Self
append only.Sourcepub fn append<T: Serialize + ?Sized + 'static>(value: &T) -> Self
Available on crate feature append only.
pub fn append<T: Serialize + ?Sized + 'static>(value: &T) -> Self
append only.Creates a Mutations containing a single Append mutation
with the given value.
The value is wrapped in a Box<dyn Serialize> via
[SerializeRef], allowing unsized types like str and [T] to be used.
Trait Implementations§
Source§impl<V> From<MutationKind<V>> for Mutations<V>
impl<V> From<MutationKind<V>> for Mutations<V>
Source§fn from(kind: MutationKind<V>) -> Self
fn from(kind: MutationKind<V>) -> Self
impl<V: Eq> Eq for Mutations<V>
impl<V> StructuralPartialEq for Mutations<V>
Auto Trait Implementations§
impl<V> Freeze for Mutations<V>where
V: Freeze,
impl<V> RefUnwindSafe for Mutations<V>where
V: RefUnwindSafe,
impl<V> Send for Mutations<V>where
V: Send,
impl<V> Sync for Mutations<V>where
V: Sync,
impl<V> Unpin for Mutations<V>where
V: Unpin,
impl<V> UnsafeUnpin for Mutations<V>where
V: UnsafeUnpin,
impl<V> UnwindSafe for Mutations<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsDerefCoinductive<Zero> for Twhere
T: ?Sized,
impl<T> AsDerefCoinductive<Zero> for Twhere
T: ?Sized,
Source§impl<T> AsDerefMut<Zero> for Twhere
T: ?Sized,
impl<T> AsDerefMut<Zero> for Twhere
T: ?Sized,
Source§fn as_deref_mut(&mut self) -> &mut T
fn as_deref_mut(&mut self) -> &mut T
N times.Source§impl<T> AsDerefMutCoinductive<Zero> for Twhere
T: ?Sized,
impl<T> AsDerefMutCoinductive<Zero> for Twhere
T: ?Sized,
Source§fn as_deref_mut_coinductive(&mut self) -> &mut T
fn as_deref_mut_coinductive(&mut self) -> &mut T
N times.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.