Skip to main content

VacantEntry

Struct VacantEntry 

Source
pub struct VacantEntry<'a, P, Tag, K>
where P: Pointer, P::Target: AvlItem<Tag>,
{ /* private fields */ }
Expand description

§Examples

use embed_avl::{AvlTree, AvlItem, AvlNode, Entry};
use core::cell::UnsafeCell;
use core::borrow::Borrow;
extern crate alloc;
use alloc::sync::Arc;

struct MyNode {
    value: i32,
    avl_node: UnsafeCell<AvlNode<MyNode, ()>>,
}

unsafe impl AvlItem<()> for MyNode {

    fn get_node(&self) -> &mut AvlNode<MyNode, ()> {
        unsafe { &mut *self.avl_node.get() }
    }
}
impl Borrow<i32> for MyNode {
    fn borrow(&self) -> &i32 {
        &self.value
    }
}

let mut tree = AvlTree::<Arc<MyNode>, ()>::new();
let key = 42;
if let Entry::Vacant(ent) = tree.entry(key) {
    ent.insert_node(Arc::new(MyNode {
        value: key,
        avl_node: UnsafeCell::new(Default::default()),
    }));
}

Implementations§

Source§

impl<'a, P, Tag, K> VacantEntry<'a, P, Tag, K>
where P: Pointer, P::Target: AvlItem<Tag>,

Source

pub fn nearest(&self) -> Option<&P::Target>

Return the nearest node in the search result

Source

pub fn peek_prev(&self) -> Option<&P::Target>

Source

pub fn key(&self) -> &K

Source

pub fn peek_next(&self) -> Option<&P::Target>

Source

pub fn move_prev(self) -> Option<OccupiedEntry<'a, P, Tag>>

Source

pub fn move_next(self) -> Option<OccupiedEntry<'a, P, Tag>>

Source

pub unsafe fn insert_node_unchecked( self, new_node: P, ) -> OccupiedEntry<'a, P, Tag>

§Safety

Caller should make sure new_node have the same value to the search key to entry(),

ignoring K captured in VacantEntry

Source§

impl<'a, P, Tag, K> VacantEntry<'a, P, Tag, K>
where P: Pointer, P::Target: AvlItem<Tag> + Borrow<K>, K: PartialEq,

Source

pub fn insert_node(self, new_node: P) -> OccupiedEntry<'a, P, Tag>

insert new_node at the position, for entry search by borrowed key

§Safety

We have debug_assert_eq the key an the node

Auto Trait Implementations§

§

impl<'a, P, Tag, K> !Send for VacantEntry<'a, P, Tag, K>

§

impl<'a, P, Tag, K> !Sync for VacantEntry<'a, P, Tag, K>

§

impl<'a, P, Tag, K> !UnwindSafe for VacantEntry<'a, P, Tag, K>

§

impl<'a, P, Tag, K> Freeze for VacantEntry<'a, P, Tag, K>
where <P as Pointer>::Target: Sized, *mut <P as Pointer>::Target: Freeze, &'a mut AvlTree<P, Tag>: Freeze, K: Freeze,

§

impl<'a, P, Tag, K> RefUnwindSafe for VacantEntry<'a, P, Tag, K>
where <P as Pointer>::Target: Sized, *mut <P as Pointer>::Target: RefUnwindSafe, &'a mut AvlTree<P, Tag>: RefUnwindSafe, K: RefUnwindSafe,

§

impl<'a, P, Tag, K> Unpin for VacantEntry<'a, P, Tag, K>
where <P as Pointer>::Target: Sized, *mut <P as Pointer>::Target: Unpin, &'a mut AvlTree<P, Tag>: Unpin, K: Unpin,

§

impl<'a, P, Tag, K> UnsafeUnpin for VacantEntry<'a, P, Tag, K>
where <P as Pointer>::Target: Sized, *mut <P as Pointer>::Target: UnsafeUnpin, &'a mut AvlTree<P, Tag>: UnsafeUnpin, K: UnsafeUnpin,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.