Struct matrix_sdk_base::linked_chunk::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 len(&self) -> usize

Get the number of items in this linked chunk.

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 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(…).

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 if 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 if 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, 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,

§

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

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

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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

source§

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

source§

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