pub struct Mutations<V> { /* private fields */ }Expand description
A collection of mutations collected during observation.
It is the return type for 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.
§Example
use morphix::{Mutation, MutationKind, Mutations};
let mut mutations = Mutations::new();
mutations.insert("a", MutationKind::Replace(42).into());
mutations.insert("b", MutationKind::Truncate(1).into());
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(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new empty collection with a specified capacity hint.
The capacity hint is used when the internal storage needs to be converted to a
Batch to hold multiple mutations.
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 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: Self)
pub fn insert(&mut self, segment: impl Into<PathSegment>, mutations: 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 insert2(
&mut self,
segment1: impl Into<PathSegment>,
segment2: impl Into<PathSegment>,
mutations: Self,
)
pub fn insert2( &mut self, segment1: impl Into<PathSegment>, segment2: impl Into<PathSegment>, mutations: Self, )
Inserts mutations at a two-level path.
This is a convenience method primarily used for enum named variants, where mutations need to
be inserted at a path like variant_name.field_name.
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.
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> 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.