pub struct CursorMut<'a, I, M>{ /* private fields */ }
Expand description
A CursorMut
can traverse in the XArray
by setting or increasing the target index and can
perform read-write operations to the target item represented by the target index.
CursorMut
s act like exclusive references, so multiple cursors are not allowed to operate on a
single XArray
at the same time.
The typical way to obtain a CursorMut
instance is to call XArray::cursor_mut
.
Features for COW (Copy-On-Write). Due to COW, multiple XArray
s can share the same piece
of data. As a result, CursorMut
does not always have exclusive access to the items stored in
the XArray
. However, just before performing the modification, CursorMut
will create
exclusive copies by cloning shared items, which guarantees the isolation of data stored in
different XArray
s.
Implementations§
source§impl<'a, I: ItemEntry, M: Into<XMark>> CursorMut<'a, I, M>
impl<'a, I: ItemEntry, M: Into<XMark>> CursorMut<'a, I, M>
sourcepub fn reset_to(&mut self, index: u64)
pub fn reset_to(&mut self, index: u64)
Resets the target index to index
.
Once set, the cursor will be positioned on the corresponding leaf node, if the leaf node exists.
sourcepub fn next(&mut self)
pub fn next(&mut self)
Increases the target index of the cursor by one.
Once increased, the cursor will be positioned on the corresponding leaf node, if the leaf node exists.
sourcepub fn load(&mut self) -> Option<I::Ref<'_>>
pub fn load(&mut self) -> Option<I::Ref<'_>>
Loads the item at the target index.
If the target item exists, this method will return a ItemEntry::Ref
that acts exactly
like a &'_ I
wrapped in Some(_)
. Otherwises, it will return None
.
sourcepub fn is_marked(&mut self, mark: M) -> bool
pub fn is_marked(&mut self, mark: M) -> bool
Checks whether the target item is marked with the input mark
.
If the target item does not exist, this method will also return false.
sourcepub fn store(&mut self, item: I) -> Option<I>
pub fn store(&mut self, item: I) -> Option<I>
Stores a new item
at the target index, and returns the old item if it previously exists.
sourcepub fn remove(&mut self) -> Option<I>
pub fn remove(&mut self) -> Option<I>
Removes the item at the target index, and returns the removed item if it previously exists.
sourcepub fn set_mark(&mut self, mark: M) -> Result<(), ()>
pub fn set_mark(&mut self, mark: M) -> Result<(), ()>
Sets the input mark
for the item at the target index if the target item exists, otherwise
returns an error.
sourcepub fn unset_mark(&mut self, mark: M) -> Result<(), ()>
pub fn unset_mark(&mut self, mark: M) -> Result<(), ()>
Unsets the input mark
for the item at the target index if the target item exists,
otherwise returns an error.