Skip to main content

CursorMutKey

Struct CursorMutKey 

Source
pub struct CursorMutKey<'a, K, V, A = Global>
where K: 'a, V: 'a,
{ /* private fields */ }
๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)
Expand description

A cursor over a BTreeMap with editing operations, and which allows mutating the key of elements.

A Cursor is like an iterator, except that it can freely seek back-and-forth, and can safely mutate the map during iteration. This is because the lifetime of its yielded references is tied to its own lifetime, instead of just the underlying map. This means cursors cannot yield multiple elements at once.

Cursors always point to a gap between two elements in the map, and can operate on the two immediately adjacent elements.

A CursorMutKey is created from a CursorMut with the CursorMut::with_mutable_key method.

ยงSafety

Since this cursor allows mutating keys, you must ensure that the BTreeMap invariants are maintained. Specifically:

  • The key of the newly inserted element must be unique in the tree.
  • All keys in the tree must remain in sorted order.

Implementationsยง

Sourceยง

impl<'a, K, V, A> CursorMutKey<'a, K, V, A>

Source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Advances the cursor to the next gap, returning the key and value of the element that it moved over.

If the cursor is already at the end of the map then None is returned and the cursor is not moved.

Source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Advances the cursor to the previous gap, returning the key and value of the element that it moved over.

If the cursor is already at the start of the map then None is returned and the cursor is not moved.

Source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Returns a reference to the key and value of the next element without moving the cursor.

If the cursor is at the end of the map then None is returned.

Source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Returns a reference to the key and value of the previous element without moving the cursor.

If the cursor is at the start of the map then None is returned.

Source

pub fn as_cursor(&self) -> Cursor<'_, K, V>

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Returns a read-only cursor pointing to the same location as the CursorMutKey.

The lifetime of the returned Cursor is bound to that of the CursorMutKey, which means it cannot outlive the CursorMutKey and that the CursorMutKey is frozen for the lifetime of the Cursor.

Sourceยง

impl<'a, K, V, A> CursorMutKey<'a, K, V, A>
where K: Ord, A: Allocator + Clone,

Source

pub unsafe fn insert_after_unchecked(&mut self, key: K, value: V)

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Inserts a new key-value pair into the map in the gap that the cursor is currently pointing to.

After the insertion the cursor will be pointing at the gap before the newly inserted element.

ยงSafety

You must ensure that the BTreeMap invariants are maintained. Specifically:

  • The key of the newly inserted element must be unique in the tree.
  • All keys in the tree must remain in sorted order.
Source

pub unsafe fn insert_before_unchecked(&mut self, key: K, value: V)

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Inserts a new key-value pair into the map in the gap that the cursor is currently pointing to.

After the insertion the cursor will be pointing at the gap after the newly inserted element.

ยงSafety

You must ensure that the BTreeMap invariants are maintained. Specifically:

  • The key of the newly inserted element must be unique in the tree.
  • All keys in the tree must remain in sorted order.
Source

pub fn insert_after( &mut self, key: K, value: V, ) -> Result<(), UnorderedKeyError>

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Inserts a new key-value pair into the map in the gap that the cursor is currently pointing to.

After the insertion the cursor will be pointing at the gap before the newly inserted element.

If the inserted key is not greater than the key before the cursor (if any), or if it not less than the key after the cursor (if any), then an UnorderedKeyError is returned since this would invalidate the Ord invariant between the keys of the map.

Source

pub fn insert_before( &mut self, key: K, value: V, ) -> Result<(), UnorderedKeyError>

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Inserts a new key-value pair into the map in the gap that the cursor is currently pointing to.

After the insertion the cursor will be pointing at the gap after the newly inserted element.

If the inserted key is not greater than the key before the cursor (if any), or if it not less than the key after the cursor (if any), then an UnorderedKeyError is returned since this would invalidate the Ord invariant between the keys of the map.

Source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Removes the next element from the BTreeMap.

The element that was removed is returned. The cursor position is unchanged (before the removed element).

Source

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

๐Ÿ”ฌThis is a nightly-only experimental API. (btree_cursors)

Removes the preceding element from the BTreeMap.

The element that was removed is returned. The cursor position is unchanged (after the removed element).

Trait Implementationsยง

Sourceยง

impl<K, V, A> Debug for CursorMutKey<'_, K, V, A>
where K: Debug, V: Debug,

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementationsยง

ยง

impl<'a, K, V, A> Freeze for CursorMutKey<'a, K, V, A>

ยง

impl<'a, K, V, A> RefUnwindSafe for CursorMutKey<'a, K, V, A>

ยง

impl<'a, K, V, A> Send for CursorMutKey<'a, K, V, A>
where A: Send, K: Send, V: Send,

ยง

impl<'a, K, V, A> Sync for CursorMutKey<'a, K, V, A>
where A: Sync, K: Sync, V: Sync,

ยง

impl<'a, K, V, A> Unpin for CursorMutKey<'a, K, V, A>

ยง

impl<'a, K, V, A> UnsafeUnpin for CursorMutKey<'a, K, V, A>

ยง

impl<'a, K, V, A = Global> !UnwindSafe for CursorMutKey<'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> DebugExt<T> for T
where T: Debug,

Sourceยง

impl<T> Downcast for T
where T: Any,

Sourceยง

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Anyโ€™s vtable from &Traitโ€™s.
Sourceยง

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Anyโ€™s vtable from &mut Traitโ€™s.
Sourceยง

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Sourceยง

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> โ“˜

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Sourceยง

impl<A> DynCastExt for A

Sourceยง

fn dyn_cast<T>( self, ) -> Result<<A as DynCastExtHelper<T>>::Target, <A as DynCastExtHelper<T>>::Source>
where A: DynCastExtHelper<T>, T: ?Sized,

Use this to cast from one trait object type to another. Read more
Sourceยง

fn dyn_upcast<T>(self) -> <A as DynCastExtAdvHelper<T, T>>::Target
where A: DynCastExtAdvHelper<T, T, Source = <A as DynCastExtAdvHelper<T, T>>::Target>, T: ?Sized,

Use this to upcast a trait to one of its supertraits. Read more
Sourceยง

fn dyn_cast_adv<F, T>( self, ) -> Result<<A as DynCastExtAdvHelper<F, T>>::Target, <A as DynCastExtAdvHelper<F, T>>::Source>
where A: DynCastExtAdvHelper<F, T>, F: ?Sized, T: ?Sized,

Use this to cast from one trait object type to another. This method is more customizable than the dyn_cast method. Here you can also specify the โ€œsourceโ€ trait from which the cast is defined. This can for example allow using casts from a supertrait of the current trait object. Read more
Sourceยง

fn dyn_cast_with_config<C>( self, ) -> Result<<A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Target, <A as DynCastExtAdvHelper<<C as DynCastConfig>::Source, <C as DynCastConfig>::Target>>::Source>

Use this to cast from one trait object type to another. With this method the type parameter is a config type that uniquely specifies which cast should be preformed. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self> โ“˜

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self> โ“˜

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Sourceยง

fn into_either(self, into_left: bool) -> Either<Self, Self> โ“˜

Converts 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 more
Sourceยง

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ“˜
where F: FnOnce(&Self) -> bool,

Converts 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
Sourceยง

impl<T> Pointable for T

Sourceยง

const ALIGN: usize

The alignment of pointer.
Sourceยง

type Init = T

The type for initializers.
Sourceยง

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Sourceยง

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Sourceยง

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Sourceยง

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Sourceยง

impl<T> Same for T

Sourceยง

type Output = T

Should always be Self
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.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V

Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> โ“˜
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self> โ“˜

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more