ObservableVector

Struct ObservableVector 

Source
pub struct ObservableVector<T> { /* private fields */ }
Expand description

An ordered list of elements that broadcasts any changes made to it.

Implementations§

Source§

impl<T: Clone + 'static> ObservableVector<T>

Source

pub fn new() -> Self

Create a new ObservableVector.

As of the time of writing, this is equivalent to ObservableVector::with_capacity(16), but the internal buffer capacity is subject to change in non-breaking releases.

See with_capacity for details about the buffer capacity.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new ObservableVector with the given capacity for the inner buffer.

Up to capacity updates that have not been received by all of the subscribers yet will be retained in the inner buffer. If an update happens while the buffer is at capacity, the oldest update is discarded from it and all subscribers that have not yet received it will instead see VectorDiff::Reset as the next update.

§Panics

Panics if the capacity is 0, or overflows.

Source

pub fn into_inner(self) -> Vector<T>

Turn the ObservableVector back into a regular Vector.

Source

pub fn subscribe(&self) -> VectorSubscriber<T>

Obtain a new subscriber.

If you put the ObservableVector behind a lock, it is highly recommended to make access of the elements and subscribing one operation. Otherwise, the values could be altered in between the reading of the values and subscribing to changes.

Source

pub fn append(&mut self, values: Vector<T>)

Append the given elements at the end of the Vector and notify subscribers.

Source

pub fn clear(&mut self)

Clear out all of the elements in this Vector and notify subscribers.

Source

pub fn push_front(&mut self, value: T)

Add an element at the front of the list and notify subscribers.

Source

pub fn push_back(&mut self, value: T)

Add an element at the back of the list and notify subscribers.

Source

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.

Source

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.

Source

pub fn insert(&mut self, index: usize, value: T)

Insert an element at the given position and notify subscribers.

§Panics

Panics if index > len.

Source

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.

Source

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.

Source

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.

Source

pub fn entry(&mut self, index: usize) -> ObservableVectorEntry<'_, 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.

Source

pub fn for_each(&mut self, f: impl FnMut(ObservableVectorEntry<'_, 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.

Source

pub fn entries(&mut self) -> ObservableVectorEntries<'_, 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
}
Source

pub fn transaction(&mut self) -> ObservableVectorTransaction<'_, T>

Start a new transaction to make multiple updates as one unit.

See ObservableVectorTransactions documentation for more details.

Trait Implementations§

Source§

impl<T> Debug for ObservableVector<T>
where T: Debug,

Source§

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

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

impl<T: Clone + 'static> Default for ObservableVector<T>

Source§

fn default() -> Self

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

impl<T> Deref for ObservableVector<T>

Source§

type Target = GenericVector<T, ArcK>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: Clone + 'static> From<GenericVector<T, ArcK>> for ObservableVector<T>

Source§

fn from(values: Vector<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for ObservableVector<T>

§

impl<T> !RefUnwindSafe for ObservableVector<T>

§

impl<T> Send for ObservableVector<T>
where T: Send + Sync,

§

impl<T> Sync for ObservableVector<T>
where T: Sync + Send,

§

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

§

impl<T> !UnwindSafe for ObservableVector<T>

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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