Struct CursorMut

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

Source

pub fn is_end(&self) -> bool

Returns true if the cursor points to the end of the tree.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn remove(&mut self) -> (K, V)

Removes the element that the cursor is currently pointing to and returns it.

After removal the cursor will point to the element after the current one.

§Panics

Panics if the cursor is pointing to the end of the tree.

Auto Trait Implementations§

§

impl<'a, K, V, A> Freeze for CursorMut<'a, K, V, A>
where <<K as BTreeKey>::Int as BTreeInteger>::Stack: Freeze,

§

impl<'a, K, V, A> RefUnwindSafe for CursorMut<'a, K, V, A>
where <<K as BTreeKey>::Int as BTreeInteger>::Stack: RefUnwindSafe, A: RefUnwindSafe, <K as BTreeKey>::Int: RefUnwindSafe, V: RefUnwindSafe,

§

impl<'a, K, V, A> Send for CursorMut<'a, K, V, A>
where <<K as BTreeKey>::Int as BTreeInteger>::Stack: Send, A: Send, V: Send,

§

impl<'a, K, V, A> Sync for CursorMut<'a, K, V, A>
where <<K as BTreeKey>::Int as BTreeInteger>::Stack: Sync, A: Sync, V: Sync,

§

impl<'a, K, V, A> Unpin for CursorMut<'a, K, V, A>
where <<K as BTreeKey>::Int as BTreeInteger>::Stack: Unpin,

§

impl<'a, K, V, A = Global> !UnwindSafe for CursorMut<'a, K, V, A>

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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