Skip to main content

Entry

Enum Entry 

Source
pub enum Entry<'a, K: Key + 'static, V: Value + 'static> {
    Occupied(OccupiedEntry<'a, K, V>),
    Vacant(VacantEntry<'a, K, V>),
}
Expand description

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

This enum is constructed from the entry method on Table, and mirrors std::collections::btree_map::Entry as closely as the redb data model allows.

Unlike the in-memory BTreeMap, redb values are stored serialized, so methods that produce a “reference to the value” return an AccessGuardMut instead of &mut V.

Variants§

§

Occupied(OccupiedEntry<'a, K, V>)

An occupied entry.

§

Vacant(VacantEntry<'a, K, V>)

A vacant entry.

Implementations§

Source§

impl<'a, K: Key + 'static, V: Value + 'static> Entry<'a, K, V>

Source

pub fn key(&self) -> &K::SelfType<'a>

Returns a view of this entry’s key.

Source

pub fn or_insert<'v>( self, default: impl Borrow<V::SelfType<'v>>, ) -> Result<AccessGuardMut<'a, V>>

Ensures a value is in the entry by inserting the provided default if empty, and returns a mutable accessor to the value in the entry.

Source

pub fn or_insert_with<'v, F, B>( self, default: F, ) -> Result<AccessGuardMut<'a, V>>
where F: FnOnce() -> B, B: Borrow<V::SelfType<'v>>,

Ensures a value is in the entry by inserting the result of default if empty, and returns a mutable accessor to the value in the entry.

Unlike or_insert, the default value is only computed if the entry is vacant.

Source

pub fn or_insert_with_key<'v, F, B>( self, default: F, ) -> Result<AccessGuardMut<'a, V>>
where F: FnOnce(&K::SelfType<'a>) -> B, B: Borrow<V::SelfType<'v>>,

Ensures a value is in the entry by inserting, if empty, the result of the default function, which is given a view of the key.

Source

pub fn and_modify<F>(self, f: F) -> Result<Self>
where F: FnOnce(&mut AccessGuardMut<'_, V>) -> Result<()>,

Provides in-place mutable access to an occupied entry before any potential inserts into the table.

The closure receives an AccessGuardMut and may replace the stored value via AccessGuardMut::insert. Any errors returned by the closure are propagated.

Auto Trait Implementations§

§

impl<'a, K, V> !RefUnwindSafe for Entry<'a, K, V>

§

impl<'a, K, V> !UnwindSafe for Entry<'a, K, V>

§

impl<'a, K, V> Freeze for Entry<'a, K, V>
where OccupiedEntry<'a, K, V>: Freeze, VacantEntry<'a, K, V>: Freeze,

§

impl<'a, K, V> Send for Entry<'a, K, V>
where OccupiedEntry<'a, K, V>: Send, VacantEntry<'a, K, V>: Send,

§

impl<'a, K, V> Sync for Entry<'a, K, V>
where OccupiedEntry<'a, K, V>: Sync, VacantEntry<'a, K, V>: Sync,

§

impl<'a, K, V> Unpin for Entry<'a, K, V>
where OccupiedEntry<'a, K, V>: Unpin, VacantEntry<'a, K, V>: Unpin,

§

impl<'a, K, V> UnsafeUnpin for Entry<'a, K, V>
where OccupiedEntry<'a, K, V>: UnsafeUnpin, VacantEntry<'a, K, V>: 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.