pub enum Entry<'a, K, V: Serial, S: HasStateApi> {
    Vacant(VacantEntry<'a, K, V, S>),
    Occupied(OccupiedEntry<'a, K, V, S>),
}
Expand description

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

This enum is constructed from the entry method on a StateMap type.

Variants§

§

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

§

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

Implementations§

source§

impl<'a, K, V, StateApi> Entry<'a, K, V, StateApi>where
K: Serial,
V: Serial,
StateApi: HasStateApi,

source

pub fn is_vacant(&self) -> bool

Return whether the entry is vacant.

source

pub fn is_occupied(&self) -> bool

Return whether the entry is occupied.

source

pub fn occupied_or<E>(self, e: E) -> Result<OccupiedEntry<'a, K, V, StateApi>, E>

If the entry is Occupied return Ok. Otherwise return the supplied error.

source

pub fn vacant_or<E>(self, e: E) -> Result<VacantEntry<'a, K, V, StateApi>, E>

If the entry is Vacant return Ok. Otherwise return the supplied error.

source

pub fn or_insert(self, value: V) -> OccupiedEntry<'a, K, V, StateApi>

Ensure a value is in the entry by inserting the provided value if the entry is vacant.

source

pub fn or_insert_with<F>(self, default: F) -> OccupiedEntry<'a, K, V, StateApi>where
F: FnOnce() -> V,

Ensures a value is in the entry by inserting the result of the default function if empty.

source

pub fn and_try_modify<F, E>(self, f: F) -> Result<Entry<'a, K, V, StateApi>, E>where
F: FnOnce(&mut V) -> Result<(), E>,

If the entry is occupied apply the given function to its contents. If the function returns an error the contents are not updated. If the supplied function returns an error then it should not modify the given value. If it does so than the map will become inconsistent. If the entry is vacant no changes are made.

source

pub fn and_modify<F>(self, f: F) -> Entry<'a, K, V, StateApi>where
F: FnOnce(&mut V),

If the entry is occupied apply the given function to its contents. If the entry is vacant no changes are made.

source

pub fn key(&self) -> &K

Return a reference to this entry’s key.

source§

impl<'a, K, V, StateApi> Entry<'a, K, V, StateApi>where
K: Serial,
V: Serial + Default,
StateApi: HasStateApi,

source

pub fn or_default(self) -> OccupiedEntry<'a, K, V, StateApi>

Ensures a value is in the entry by inserting the default value if empty.

Auto Trait Implementations§

§

impl<'a, K, V, S> RefUnwindSafe for Entry<'a, K, V, S>where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,
<S as HasStateApi>::EntryType: RefUnwindSafe,

§

impl<'a, K, V, S> Send for Entry<'a, K, V, S>where
K: Send,
S: Send,
V: Send,
<S as HasStateApi>::EntryType: Send,

§

impl<'a, K, V, S> Sync for Entry<'a, K, V, S>where
K: Sync,
S: Sync,
V: Sync,
<S as HasStateApi>::EntryType: Sync,

§

impl<'a, K, V, S> Unpin for Entry<'a, K, V, S>where
K: Unpin,
S: Unpin,
V: Unpin,
<S as HasStateApi>::EntryType: Unpin,

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.