matrix_sdk::linked_chunk

Struct LinkedChunk

Source
pub struct LinkedChunk<const CHUNK_CAPACITY: usize, Item, Gap> { /* private fields */ }
Expand description

The LinkedChunk structure.

It is similar to a linked list, except that it contains many items Item instead of a single one. A chunk has a maximum capacity of CHUNK_CAPACITY. Once a chunk is full, a new chunk is created. Not all chunks are necessarily entirely full. A chunk can represents a Gap between other chunks.

Implementations§

Source§

impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap>

Source

pub fn new() -> LinkedChunk<CAP, Item, Gap>

Create a new Self.

Source

pub fn new_with_update_history() -> LinkedChunk<CAP, Item, Gap>

Create a new Self with a history of updates.

When Self is built with update history, the ObservableUpdates::take method must be called to consume and clean the updates. See Self::updates.

Source

pub fn clear(&mut self)

Clear all the chunks.

Source

pub fn push_items_back<I>(&mut self, items: I)
where Item: Clone, Gap: Clone, I: IntoIterator<Item = Item>, <I as IntoIterator>::IntoIter: ExactSizeIterator,

Push items at the end of the LinkedChunk, i.e. on the last chunk.

If the last chunk doesn’t have enough space to welcome all items, then new chunks can be created (and linked appropriately).

Source

pub fn push_gap_back(&mut self, content: Gap)
where Item: Clone, Gap: Clone,

Push a gap at the end of the LinkedChunk, i.e. after the last chunk.

Source

pub fn insert_items_at<I>( &mut self, items: I, position: Position, ) -> Result<(), Error>
where Item: Clone, Gap: Clone, I: IntoIterator<Item = Item>, <I as IntoIterator>::IntoIter: ExactSizeIterator,

Insert items at a specified position in the LinkedChunk.

Because the position can be invalid, this method returns a Result.

Source

pub fn remove_item_at( &mut self, position: Position, empty_chunk: EmptyChunk, ) -> Result<Item, Error>

Remove item at a specified position in the LinkedChunk.

position must point to a valid item, otherwise the method returns Err.

The chunk containing the item represented by position may be empty once the item has been removed. In this case, the chunk can be removed if empty_chunk contains EmptyChunk::Remove, otherwise the chunk is kept if empty_chunk contains EmptyChunk::Keep.

Source

pub fn insert_gap_at( &mut self, content: Gap, position: Position, ) -> Result<(), Error>
where Item: Clone, Gap: Clone,

Insert a gap at a specified position in the LinkedChunk.

Because the position can be invalid, this method returns a Result.

Source

pub fn remove_gap_at( &mut self, chunk_identifier: ChunkIdentifier, ) -> Result<Option<Position>, Error>

Remove a gap with the given identifier.

This returns the next insert position, viz. the start of the next chunk, if any, or none if there was no next chunk.

Source

pub fn replace_gap_at<I>( &mut self, items: I, chunk_identifier: ChunkIdentifier, ) -> Result<&Chunk<CAP, Item, Gap>, Error>
where Item: Clone, Gap: Clone, I: IntoIterator<Item = Item>, <I as IntoIterator>::IntoIter: ExactSizeIterator,

Replace the gap identified by chunk_identifier, by items.

Because the chunk_identifier can represent non-gap chunk, this method returns a Result.

This method returns a reference to the (first if many) newly created Chunk that contains the items.

Source

pub fn chunk_identifier<'a, P>( &'a self, predicate: P, ) -> Option<ChunkIdentifier>
where P: FnMut(&'a Chunk<CAP, Item, Gap>) -> bool,

Search backwards for a chunk, and return its identifier.

Source

pub fn item_position<'a, P>(&'a self, predicate: P) -> Option<Position>
where P: FnMut(&'a Item) -> bool,

Search backwards for an item, and return its position.

Source

pub fn rchunks(&self) -> IterBackward<'_, CAP, Item, Gap>

Iterate over the chunks, backwards.

It iterates from the last to the first chunk.

Source

pub fn chunks(&self) -> Iter<'_, CAP, Item, Gap>

Iterate over the chunks, forward.

It iterates from the first to the last chunk.

Source

pub fn rchunks_from( &self, identifier: ChunkIdentifier, ) -> Result<IterBackward<'_, CAP, Item, Gap>, Error>

Iterate over the chunks, starting from identifier, backward.

It iterates from the chunk with the identifier identifier to the first chunk.

Source

pub fn chunks_from( &self, identifier: ChunkIdentifier, ) -> Result<Iter<'_, CAP, Item, Gap>, Error>

Iterate over the chunks, starting from position, forward.

It iterates from the chunk with the identifier identifier to the last chunk.

Source

pub fn ritems(&self) -> impl Iterator<Item = (Position, &Item)>

Iterate over the items, backward.

It iterates from the last to the first item.

Source

pub fn items(&self) -> impl Iterator<Item = (Position, &Item)>

Iterate over the items, forward.

It iterates from the first to the last item.

Source

pub fn ritems_from( &self, position: Position, ) -> Result<impl Iterator<Item = (Position, &Item)>, Error>

Iterate over the items, starting from position, backward.

It iterates from the item at position to the first item.

Source

pub fn items_from( &self, position: Position, ) -> Result<impl Iterator<Item = (Position, &Item)>, Error>

Iterate over the items, starting from position, forward.

It iterates from the item at position to the last item.

Source

pub fn updates(&mut self) -> Option<&mut ObservableUpdates<Item, Gap>>

Get a mutable reference to the LinkedChunk updates, aka ObservableUpdates.

If the Option becomes None, it will disable update history. Thus, be careful when you want to empty the update history: do not use Option::take() directly but rather ObservableUpdates::take for example.

It returns None if updates are disabled, i.e. if this linked chunk has been constructed with Self::new, otherwise, if it’s been constructed with Self::new_with_update_history, it returns Some(…).

Source

pub fn as_vector(&mut self) -> Option<AsVector<Item, Gap>>

Get updates as eyeball_im::VectorDiff, see AsVector to learn more.

It returns None if updates are disabled, i.e. if this linked chunk has been constructed with Self::new, otherwise, if it’s been constructed with Self::new_with_update_history, it returns Some(…).

Source

pub fn num_items(&self) -> usize

Returns the number of items of the linked chunk.

Trait Implementations§

Source§

impl<const CAP: usize, Item, Gap> Debug for LinkedChunk<CAP, Item, Gap>
where Item: Debug, Gap: Debug,

Source§

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

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

impl<const CAP: usize, Item, Gap> Default for LinkedChunk<CAP, Item, Gap>

Source§

fn default() -> LinkedChunk<CAP, Item, Gap>

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

impl<const CAP: usize, Item, Gap> Drop for LinkedChunk<CAP, Item, Gap>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const CAP: usize, Item, Gap> Send for LinkedChunk<CAP, Item, Gap>
where Item: Send, Gap: Send,

A LinkedChunk can be safely sent over thread boundaries if Item: Send and Gap: Send. The only unsafe part is around the NonNull, but the API and the lifetimes to deref them are designed safely.

Source§

impl<const CAP: usize, Item, Gap> Sync for LinkedChunk<CAP, Item, Gap>
where Item: Sync, Gap: Sync,

A LinkedChunk can be safely share between threads if Item: Sync and Gap: Sync. The only unsafe part is around the NonNull, but the API and the lifetimes to deref them are designed safely.

Auto Trait Implementations§

§

impl<const CHUNK_CAPACITY: usize, Item, Gap> !Freeze for LinkedChunk<CHUNK_CAPACITY, Item, Gap>

§

impl<const CHUNK_CAPACITY: usize, Item, Gap> RefUnwindSafe for LinkedChunk<CHUNK_CAPACITY, Item, Gap>
where Gap: RefUnwindSafe, Item: RefUnwindSafe,

§

impl<const CHUNK_CAPACITY: usize, Item, Gap> Unpin for LinkedChunk<CHUNK_CAPACITY, Item, Gap>

§

impl<const CHUNK_CAPACITY: usize, Item, Gap> UnwindSafe for LinkedChunk<CHUNK_CAPACITY, Item, Gap>

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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<>
Source§

fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

§

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

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

Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

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

Source§

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