pub struct ObservableVectorTransaction<'o, T: Clone> { /* private fields */ }Expand description
A transaction that allows making multiple updates to an ObservableVector
as an atomic unit.
For updates from the transaction to have affect, it has to be finalized with
.commit(). If the transaction is dropped without that
method being called, the updates will be discarded.
Implementations§
Source§impl<'o, T: Clone + 'static> ObservableVectorTransaction<'o, T>
impl<'o, T: Clone + 'static> ObservableVectorTransaction<'o, T>
Sourcepub fn rollback(&mut self)
pub fn rollback(&mut self)
Roll back all changes made using this transaction so far.
Same as dropping the transaction and starting a new one, semantically.
Sourcepub fn append(&mut self, values: Vector<T>)
pub fn append(&mut self, values: Vector<T>)
Append the given elements at the end of the Vector and notify
subscribers.
Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Add an element at the front of the list and notify subscribers.
Sourcepub fn push_back(&mut self, value: T)
pub fn push_back(&mut self, value: T)
Add an element at the back of the list and notify subscribers.
Sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Remove the first element, notify subscribers and return the element.
If there are no elements, subscribers will not be notified and this
method will return None.
Sourcepub fn pop_back(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
Remove the last element, notify subscribers and return the element.
If there are no elements, subscribers will not be notified and this
method will return None.
Sourcepub fn set(&mut self, index: usize, value: T) -> T
pub fn set(&mut self, index: usize, value: T) -> T
Replace the element at the given position, notify subscribers and return the previous element at that position.
§Panics
Panics if index >= len.
Sourcepub fn remove(&mut self, index: usize) -> T
pub fn remove(&mut self, index: usize) -> T
Remove the element at the given position, notify subscribers and return the element.
§Panics
Panics if index >= len.
Sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Truncate the vector to len elements and notify subscribers.
Does nothing if len is greater or equal to the vector’s current
length.
Sourcepub fn entry(
&mut self,
index: usize,
) -> ObservableVectorTransactionEntry<'_, 'o, T>
pub fn entry( &mut self, index: usize, ) -> ObservableVectorTransactionEntry<'_, 'o, T>
Gets an entry for the given index through which only the element at that index alone can be updated or removed.
§Panics
Panics if index >= len.
Sourcepub fn for_each(
&mut self,
f: impl FnMut(ObservableVectorTransactionEntry<'_, 'o, T>),
)
pub fn for_each( &mut self, f: impl FnMut(ObservableVectorTransactionEntry<'_, 'o, T>), )
Call the given closure for every element in this ObservableVector,
with an entry struct that allows updating or removing that element.
Iteration happens in order, i.e. starting at index 0.
Sourcepub fn entries(&mut self) -> ObservableVectorTransactionEntries<'_, 'o, T>
pub fn entries(&mut self) -> ObservableVectorTransactionEntries<'_, 'o, T>
Get an iterator over all the entries in this ObservableVector.
This is a more flexible, but less convenient alternative to
for_each. If you don’t need to use special control
flow like .await or break when iterating, it’s recommended to use
that method instead.
Because std’s Iterator trait does not allow iterator items to borrow
from the iterator itself, the returned typed does not implement the
Iterator trait and can thus not be used with a for loop. Instead,
you have to call its .next() method directly, as in:
let mut entries = ob.entries();
while let Some(entry) = entries.next() {
// use entry
}