Enum VecMutation
pub enum VecMutation<T>where
T: Clone,{
}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,
impl<T> VecMutation<T>where
T: Clone,
pub fn apply(self, list: &mut Vec<T>)
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>
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>
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>
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,
impl<T> Clone for VecMutation<T>where
T: Clone,
§fn clone(&self) -> VecMutation<T>
fn clone(&self) -> VecMutation<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<T> Debug for VecMutation<T>
impl<T> Debug for VecMutation<T>
§impl From<VecMutation<Bot>> for ChatStateMutation
impl From<VecMutation<Bot>> for ChatStateMutation
§fn from(mutation: VecMutation<Bot>) -> ChatStateMutation
fn from(mutation: VecMutation<Bot>) -> ChatStateMutation
§impl From<VecMutation<Message>> for ChatStateMutation
impl From<VecMutation<Message>> for ChatStateMutation
§fn from(mutation: VecMutation<Message>) -> ChatStateMutation
fn from(mutation: VecMutation<Message>) -> ChatStateMutation
§impl<T> PartialEq for VecMutation<T>
impl<T> PartialEq for VecMutation<T>
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
impl<T> ActionTrait for T
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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.