Struct hashlink::linked_hash_map::CursorMut

source ·
pub struct CursorMut<'a, K, V, S> { /* private fields */ }
Expand description

The CursorMut struct and its implementation provide the basic mutable Cursor API for Linked lists as proposed in here, with several exceptions:

  • It behaves similarly to Rust’s Iterators, returning None when the end of the list is reached. A guard node is positioned between the head and tail of the linked list to facilitate this. If the cursor is over this guard node, None is returned, signaling the end or start of the list. From this position, the cursor can move in either direction as the linked list is circular, with the guard node connecting the two ends.
  • The current implementation does not include an index method, as it does not track the index of its elements. It provides access to each map entry as a tuple of (&K, &mut V).

Implementations§

source§

impl<'a, K, V, S> CursorMut<'a, K, V, S>

source

pub fn current(&mut self) -> Option<(&K, &mut V)>

Returns an Option of the current element in the list, provided it is not the guard node, and None overwise.

source

pub fn peek_next(&mut self) -> Option<(&K, &mut V)>

Retrieves the next element in the list (moving towards the end).

source

pub fn peek_prev(&mut self) -> Option<(&K, &mut V)>

Retrieves the previous element in the list (moving towards the front).

source

pub fn move_next(&mut self)

Updates the pointer to the current element to the next element in the list (that is, moving towards the end).

source

pub fn move_prev(&mut self)

Updates the pointer to the current element to the previous element in the list (that is, moving towards the front).

source

pub fn insert_before(&mut self, key: K, value: V) -> Option<V>
where K: Eq + Hash, S: BuildHasher,

Inserts the provided key and value before the current element. It checks if an entry with the given key exists and, if so, replaces its value with the provided key parameter. The key is not updated; this matters for types that can be == without being identical.

If the entry doesn’t exist, it creates a new one. If a value has been updated, the function returns the old value wrapped with Some and None otherwise.

source

pub fn insert_after(&mut self, key: K, value: V) -> Option<V>
where K: Eq + Hash, S: BuildHasher,

Inserts the provided key and value after the current element. It checks if an entry with the given key exists and, if so, replaces its value with the provided key parameter. The key is not updated; this matters for types that can be == without being identical.

If the entry doesn’t exist, it creates a new one. If a value has been updated, the function returns the old value wrapped with Some and None otherwise.

Auto Trait Implementations§

§

impl<'a, K, V, S> Freeze for CursorMut<'a, K, V, S>

§

impl<'a, K, V, S> RefUnwindSafe for CursorMut<'a, K, V, S>

§

impl<'a, K, V, S> !Send for CursorMut<'a, K, V, S>

§

impl<'a, K, V, S> !Sync for CursorMut<'a, K, V, S>

§

impl<'a, K, V, S> Unpin for CursorMut<'a, K, V, S>

§

impl<'a, K, V, S> !UnwindSafe for CursorMut<'a, K, V, S>

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

§

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.