pub struct CursorMut<'a, K: BTreeKey, V, A: Allocator = Global> { /* private fields */ }
Expand description
A mutable cursor over the elements of a BTree
which allows editing
operations.
Cursors point either to an element in the tree or to the end of the tree.
Iterators are more efficient than cursors. Prefer using them if you don’t need reverse iteration or if you don’t need to insert or remove elements in the tree.
This type is returned by BTree::cursor_mut_at
and BTree::cursor_mut
.
Implementations§
Source§impl<'a, K: BTreeKey, V, A: Allocator> CursorMut<'a, K, V, A>
impl<'a, K: BTreeKey, V, A: Allocator> CursorMut<'a, K, V, A>
Sourcepub fn key(&self) -> Option<K>
pub fn key(&self) -> Option<K>
Returns the key of the element that the cursor is currently pointing to,
or None
if the cursor is pointing to the end of the tree.
Sourcepub fn value(&self) -> Option<&V>
pub fn value(&self) -> Option<&V>
Returns a reference to the value that the cursor is currently
pointing to, or None
if the cursor is pointing to the end of the tree.
Sourcepub fn value_mut(&mut self) -> Option<&mut V>
pub fn value_mut(&mut self) -> Option<&mut V>
Returns a mutable reference to the value that the cursor is currently
pointing to, or None
if the cursor is pointing to the end of the tree.
Sourcepub fn entry(&self) -> Option<(K, &V)>
pub fn entry(&self) -> Option<(K, &V)>
Returns the key and a reference to the value that the cursor is
currently pointing to, or None
if the cursor is pointing to the end of
the tree.
Sourcepub fn entry_mut(&mut self) -> Option<(K, &mut V)>
pub fn entry_mut(&mut self) -> Option<(K, &mut V)>
Returns the key and a mutable reference to the value that the cursor is
currently pointing to, or None
if the cursor is pointing to the end of
the tree.
Sourcepub fn next(&mut self)
pub fn next(&mut self)
Advances the cursor to the next element in the tree.
§Panics
Panics if the cursor is pointing to the end of the tree.
Sourcepub fn prev(&mut self) -> bool
pub fn prev(&mut self) -> bool
Advances the cursor to the previous element in the tree.
If the cursor is already at the first element of the tree then this
method returns false
and the cursor position is not moved.
Sourcepub fn iter(&self) -> Iter<'_, K, V, A> ⓘ
pub fn iter(&self) -> Iter<'_, K, V, A> ⓘ
Returns an iterator starting a the current element.
Iterators are more efficient than cursors. Prefer using them if you don’t need reverse iteration or if you don’t need to insert or remove elements in the tree.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V, A> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V, A> ⓘ
Returns a mutable iterator starting a the current element.
Iterators are more efficient than cursors. Prefer using them if you don’t need reverse iteration or if you don’t need to insert or remove elements in the tree.
Sourcepub fn into_iter(self) -> Iter<'a, K, V, A> ⓘ
pub fn into_iter(self) -> Iter<'a, K, V, A> ⓘ
Returns an iterator starting a the current element.
Unlike CursorMut::iter
the returned iterator has the same lifetime
as the cursor and consumes the cursor.
Iterators are more efficient than cursors. Prefer using them if you don’t need reverse iteration or if you don’t need to insert or remove elements in the tree.
Sourcepub fn into_iter_mut(self) -> IterMut<'a, K, V, A> ⓘ
pub fn into_iter_mut(self) -> IterMut<'a, K, V, A> ⓘ
Returns a mutable iterator starting a the current element.
Unlike CursorMut::iter_mut
the returned iterator has the same lifetime
as the cursor and consumes the cursor.
Iterators are more efficient than cursors. Prefer using them if you don’t need reverse iteration or if you don’t need to insert or remove elements in the tree.
Sourcepub fn insert_before(&mut self, key: K, value: V)
pub fn insert_before(&mut self, key: K, value: V)
Inserts key
and value
before the element that the cursor is
currently pointing to.
After insertion the cursor will be pointing to the newly inserted element.
If the cursor is pointing to the end of the tree then this inserts the new element at the end of the tree after all other elements.
It is the user’s responsibility to ensure that inserting key
at this
position does not violate the invariant that all keys must be in sorted
order in the tree. Violating this invariant is safe but may cause
other operations to return incorrect results or panic.
Sourcepub fn insert_after(&mut self, key: K, value: V)
pub fn insert_after(&mut self, key: K, value: V)
Inserts key
and value
after the element that the cursor is
currently pointing to.
After insertion the cursor will still be pointing to the same element as before the insertion.
It is the user’s responsibility to ensure that inserting key
at this
position does not violate the invariant that all keys must be in sorted
order in the tree. Violating this invariant is safe but may cause
other operations to return incorrect results or panic.
§Panics
Panics if the cursor is pointing to the end of the tree.
Sourcepub fn replace(&mut self, key: K, value: V) -> (K, V)
pub fn replace(&mut self, key: K, value: V) -> (K, V)
Replaces the key and value of the element that the cursor is currently pointing to and returns the previous key and value.
It is the user’s responsibility to ensure that inserting key
at this
position does not violate the invariant that all keys must be in sorted
order in the tree. Violating this invariant is safe but may cause
other operations to return incorrect results or panic.
§Panics
Panics if the cursor is pointing to the end of the tree.