VecMutation

Enum VecMutation 

pub enum VecMutation<T>
where T: Clone,
{
Show 13 variants Splice(usize, usize, Vec<T>), InsertMany(usize, Vec<T>), InsertOne(usize, T), Extend(Vec<T>), Push(T), RemoveRange(usize, usize), RemoveOne(usize), RemoveMany(IndexSet), RemoveLast, Clear, Update(usize, T), UpdateLast(T), Set(Vec<T>),
}
Expand description

Ergonomic, debuggable and loggable mutation to a Vec<T>.

Variants in this enum may represent overlapping operations as they are designed for ergonomics and clarity. To analyze the precise changes to a vector, use the [VecMutation::log] method which produces a detailed log of the changes that a mutation will apply.

Variants§

§

Splice(usize, usize, Vec<T>)

Replaces the given range with new elements.

Splice is capable of both inserting and removing elements.

When analyzed as a VecEffect, this mutation is equivalent to a Remove followed by an Insert.

§

InsertMany(usize, Vec<T>)

Inserts many elements at the given index.

Same as Splice with an empty removal range.

§

InsertOne(usize, T)

Inserts one element at the given index.

Same as [InsertMany] but for a single element.

§

Extend(Vec<T>)

Appends many elements to the end of the vec.

Similar to InsertMany but targeting the end of the vec when applied.

§

Push(T)

Appends one element to the end of the vec.

Same as Extend but for a single element.

§

RemoveRange(usize, usize)

Removes a range of elements.

Same as Splice with an empty insertion list.

§

RemoveOne(usize)

Removes a single element at the given index.

Same as RemoveRange but for a single element.

§

RemoveMany(IndexSet)

Remove many sparse elements at once.

When analyzed as a VecEffect, this mutation is equivalent to multiple sparse Removes.

Note: This is more efficient than multiple RemoveOne mutations, as all removals are performed in a single retain pass. However, building the index list itself can be expensive anyways, so use this with caution.

§

RemoveLast

Removes the last element from the vec.

When analyzed as a VecEffect, this mutation is equivalent to a Remove.

§

Clear

Removes all elements from the vec.

Same as RemoveRange targeting the full range of the vec.

§

Update(usize, T)

Updates the element at the given index.

When analyzed as a VecEffect, this mutation is equivalent to an Update.

§

UpdateLast(T)

Updates the last element in the vec.

When analyzed as a VecEffect, this mutation is equivalent to an Update.

§

Set(Vec<T>)

Replaces the entire contents of the vec with the given elements.

When analyzed as a VecEffect, this mutation is equivalent to a Remove of the full previous contents followed by an Insert of the new contents.

Implementations§

§

impl<T> VecMutation<T>
where T: Clone,

pub fn apply(self, list: &mut Vec<T>)

Apply the changes represented by this mutation to the given vec.

pub fn update_with( target: &[T], index: usize, updater: impl FnOnce(&mut T), ) -> VecMutation<T>

Use a function to craft a VecMutation::Update using mutable semantics.

This clones the target item on construction.

pub fn update_last_with( target: &[T], updater: impl FnOnce(&mut T), ) -> VecMutation<T>

Use a function to craft a VecMutation::UpdateLast using mutable semantics.

This clones the target item on construction.

pub fn remove_many_with_retain( target: &[T], retain: impl FnMut(usize, &T) -> bool, ) -> VecMutation<T>

Constructs a VecMutation::RemoveMany using retention semantics.

The retain predicate should return true for elements to keep and false for elements to remove. This matches the semantics of Rust’s standard Vec::retain method.

Warning: This will allocate a Vec to hold all the matched indices. Read the documentation of VecMutation::RemoveMany for more details.

pub fn effects<'a>( &'a self, target: &'a [T], ) -> Box<dyn Iterator<Item = VecEffect<'a, T>> + 'a>

Trait Implementations§

§

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

§

fn clone(&self) -> VecMutation<T>

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
§

impl<T> Debug for VecMutation<T>
where T: Debug + Clone,

§

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

Formats the value using the given formatter. Read more
§

impl From<VecMutation<Bot>> for ChatStateMutation

§

fn from(mutation: VecMutation<Bot>) -> ChatStateMutation

Converts to this type from the input type.
§

impl From<VecMutation<Message>> for ChatStateMutation

§

fn from(mutation: VecMutation<Message>) -> ChatStateMutation

Converts to this type from the input type.
§

impl<T> PartialEq for VecMutation<T>
where T: PartialEq + Clone,

§

fn eq(&self, other: &VecMutation<T>) -> 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.
§

impl<T> StructuralPartialEq for VecMutation<T>
where T: Clone,

Auto Trait Implementations§

§

impl<T> Freeze for VecMutation<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for VecMutation<T>
where T: RefUnwindSafe,

§

impl<T> Send for VecMutation<T>
where T: Send,

§

impl<T> Sync for VecMutation<T>
where T: Sync,

§

impl<T> Unpin for VecMutation<T>
where T: Unpin,

§

impl<T> UnwindSafe for VecMutation<T>
where T: UnwindSafe,

Blanket Implementations§

§

impl<T> ActionTrait for T
where T: 'static + Debug + ?Sized,

§

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

§

fn ref_cast_type_id(&self) -> TypeId
where Self: 'static,

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> 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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WidgetActionTrait for T
where T: 'static + Clone + Debug + Send + Sync + ?Sized,

§

fn ref_cast_type_id(&self) -> TypeId

§

fn box_clone(&self) -> Box<dyn WidgetActionTrait>

§

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

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> PlatformSend for T
where T: PlatformSendInner,

§

impl<T> PlatformSendInner for T
where T: Send,