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>
impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap>
Sourcepub fn new() -> LinkedChunk<CAP, Item, Gap>
pub fn new() -> LinkedChunk<CAP, Item, Gap>
Create a new Self
.
Sourcepub fn new_with_update_history() -> LinkedChunk<CAP, Item, Gap>
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
.
Sourcepub fn push_items_back<I>(&mut self, items: I)where
Item: Clone,
Gap: Clone,
I: IntoIterator<Item = Item>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
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).
Sourcepub fn push_gap_back(&mut self, content: Gap)
pub fn push_gap_back(&mut self, content: Gap)
Push a gap at the end of the LinkedChunk
, i.e. after the last
chunk.
Sourcepub 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,
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
.
Sourcepub fn remove_item_at(
&mut self,
position: Position,
empty_chunk: EmptyChunk,
) -> Result<Item, Error>
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
.
Sourcepub fn insert_gap_at(
&mut self,
content: Gap,
position: Position,
) -> Result<(), Error>
pub fn insert_gap_at( &mut self, content: Gap, position: Position, ) -> Result<(), Error>
Insert a gap at a specified position in the LinkedChunk
.
Because the position
can be invalid, this method returns a
Result
.
Sourcepub 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,
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
.
Sourcepub fn chunk_identifier<'a, P>(
&'a self,
predicate: P,
) -> Option<ChunkIdentifier>
pub fn chunk_identifier<'a, P>( &'a self, predicate: P, ) -> Option<ChunkIdentifier>
Search backwards for a chunk, and return its identifier.
Sourcepub fn item_position<'a, P>(&'a self, predicate: P) -> Option<Position>
pub fn item_position<'a, P>(&'a self, predicate: P) -> Option<Position>
Search backwards for an item, and return its position.
Sourcepub fn rchunks(&self) -> IterBackward<'_, CAP, Item, Gap> ⓘ
pub fn rchunks(&self) -> IterBackward<'_, CAP, Item, Gap> ⓘ
Iterate over the chunks, backwards.
It iterates from the last to the first chunk.
Sourcepub fn chunks(&self) -> Iter<'_, CAP, Item, Gap> ⓘ
pub fn chunks(&self) -> Iter<'_, CAP, Item, Gap> ⓘ
Iterate over the chunks, forward.
It iterates from the first to the last chunk.
Sourcepub fn rchunks_from(
&self,
identifier: ChunkIdentifier,
) -> Result<IterBackward<'_, CAP, Item, Gap>, Error>
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.
Sourcepub fn chunks_from(
&self,
identifier: ChunkIdentifier,
) -> Result<Iter<'_, CAP, Item, Gap>, Error>
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.
Sourcepub fn ritems(&self) -> impl Iterator<Item = (Position, &Item)>
pub fn ritems(&self) -> impl Iterator<Item = (Position, &Item)>
Iterate over the items, backward.
It iterates from the last to the first item.
Sourcepub fn items(&self) -> impl Iterator<Item = (Position, &Item)>
pub fn items(&self) -> impl Iterator<Item = (Position, &Item)>
Iterate over the items, forward.
It iterates from the first to the last item.
Sourcepub fn ritems_from(
&self,
position: Position,
) -> Result<impl Iterator<Item = (Position, &Item)>, Error>
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.
Sourcepub fn items_from(
&self,
position: Position,
) -> Result<impl Iterator<Item = (Position, &Item)>, Error>
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.
Sourcepub fn updates(&mut self) -> Option<&mut ObservableUpdates<Item, Gap>>
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(…)
.
Sourcepub fn as_vector(&mut self) -> Option<AsVector<Item, Gap>>
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>
impl<const CAP: usize, Item, Gap> Debug for LinkedChunk<CAP, Item, Gap>
Source§impl<const CAP: usize, Item, Gap> Default for LinkedChunk<CAP, Item, Gap>
impl<const CAP: usize, Item, Gap> Default for LinkedChunk<CAP, Item, Gap>
Source§fn default() -> LinkedChunk<CAP, Item, Gap>
fn default() -> LinkedChunk<CAP, Item, Gap>
Source§impl<const CAP: usize, Item, Gap> Drop for LinkedChunk<CAP, Item, Gap>
impl<const CAP: usize, Item, Gap> Drop for LinkedChunk<CAP, Item, Gap>
impl<const CAP: usize, Item, Gap> Send for LinkedChunk<CAP, Item, Gap>
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.
impl<const CAP: usize, Item, Gap> Sync for LinkedChunk<CAP, Item, Gap>
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> 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, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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