Skip to main content

Mutations

Struct Mutations 

Source
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_inner returns None.
  • 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>

Source

pub fn new() -> Self

Creates a new empty collection.

Source

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.

Source

pub fn into_inner(self) -> Option<Mutation<V>>

Consumes the batch and returns the collected mutation.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if this collection contains no mutations.

Trait Implementations§

Source§

impl<V: Clone> Clone for Mutations<V>

Source§

fn clone(&self) -> Mutations<V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Debug> Debug for Mutations<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V> Default for Mutations<V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<V> From<MutationKind<V>> for Mutations<V>

Source§

fn from(kind: MutationKind<V>) -> Self

Converts to this type from the input type.
Source§

impl<V> From<Mutations<V>> for Option<Mutation<V>>

Source§

fn from(value: Mutations<V>) -> Self

Converts to this type from the input type.
Source§

impl<V: PartialEq> PartialEq for Mutations<V>

Source§

fn eq(&self, other: &Mutations<V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<V: Eq> Eq for Mutations<V>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsDeref<Zero> for T
where T: ?Sized,

Source§

type Target = T

The target type after N dereferences.
Source§

fn as_deref(&self) -> &T

Dereferences self N times.
Source§

impl<T> AsDerefCoinductive<Zero> for T
where T: ?Sized,

Source§

type Target = T

The target type after N dereferences.
Source§

fn as_deref_coinductive(&self) -> &T

Dereferences self N times.
Source§

impl<T> AsDerefMut<Zero> for T
where T: ?Sized,

Source§

fn as_deref_mut(&mut self) -> &mut T

Mutably dereferences self N times.
Source§

impl<T> AsDerefMutCoinductive<Zero> for T
where T: ?Sized,

Source§

fn as_deref_mut_coinductive(&mut self) -> &mut T

Mutably dereferences self N times.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.