Skip to main content

Entry

Enum Entry 

Source
pub enum Entry<'t, 'e, P, A>
where P: LeafPolicy, A: TreeAllocator<P>,
{ Occupied(OccupiedEntry<'t, 'e, P, A>), Vacant(VacantEntry<'t, 'e, P, A>), }
Expand description

A view into a single entry in a tree, which may either be vacant or occupied.

§Example

use masstree::MassTree;

let tree: MassTree<u64> = MassTree::new();
let guard = tree.guard();

// Insert if absent, get value either way
let _value = tree.entry_with_guard(b"counter", &guard)
    .or_insert(0);

// Modify existing or insert default
let _value = tree.entry_with_guard(b"counter", &guard)
    .and_modify(|v| v + 1)
    .or_insert(0);

Variants§

§

Occupied(OccupiedEntry<'t, 'e, P, A>)

An occupied entry (key exists in tree at classification time).

§

Vacant(VacantEntry<'t, 'e, P, A>)

A vacant entry (key does not exist classification time).

Implementations§

Source§

impl<'t, 'e, P, A> Entry<'t, 'e, P, A>
where P: LeafPolicy, A: TreeAllocator<P>,

Source

pub const fn key(&self) -> &[u8]

Returns the key for this entry.

Source

pub fn or_insert(self, default: P::Value) -> P::Output

Fallible version or_insert.

§Errors

Panics if insertion fails (allocation error). For fallible insertion, use or_try_insert.

§Example
let value = tree.entry_with_guard(b"key", &guard).or_insert(42);

Returns the entry’s value if occupied, or inserts the default and returns it.

Source

pub fn or_insert_with<F>(self, default: F) -> P::Output
where F: FnOnce() -> P::Value,

Returns the entry’s value if occupied, or computes and inserts a default.

Source

pub fn or_insert_with_key<F>(self, default: F) -> P::Output
where F: FnOnce(&[u8]) -> P::Value,

Returns the entry’s value if occupied, or computes a default from the key.

Source

pub fn or_default(self) -> P::Output
where P::Value: Default,

Inserts the default value if vacant, returns the entry’s value.

Source

pub fn and_modify<F>(self, f: F) -> Self
where F: FnOnce(&P::Output) -> P::Value,

Modifies the value if occupied using the provided function.

Source

pub fn insert_entry(self, value: P::Value) -> OccupiedEntry<'t, 'e, P, A>

Inserts a value and returns an OccupiedEntry.

Source

pub const fn get(&self) -> Option<&P::Output>

Returns a reference to the value if occupied, or None if vacant.

Trait Implementations§

Source§

impl<P, A> Debug for Entry<'_, '_, P, A>
where P: LeafPolicy, P::Output: Send + Sync + Debug, A: TreeAllocator<P>,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'t, 'e, P, A> Freeze for Entry<'t, 'e, P, A>
where <P as LeafPolicy>::Output: Freeze,

§

impl<'t, 'e, P, A> !RefUnwindSafe for Entry<'t, 'e, P, A>

§

impl<'t, 'e, P, A> !Send for Entry<'t, 'e, P, A>

§

impl<'t, 'e, P, A> !Sync for Entry<'t, 'e, P, A>

§

impl<'t, 'e, P, A> Unpin for Entry<'t, 'e, P, A>
where <P as LeafPolicy>::Output: Unpin,

§

impl<'t, 'e, P, A> UnsafeUnpin for Entry<'t, 'e, P, A>
where <P as LeafPolicy>::Output: UnsafeUnpin,

§

impl<'t, 'e, P, A> !UnwindSafe for Entry<'t, 'e, P, 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.