[][src]Enum hetero_container::Entry

pub enum Entry<'a, V> {
    Occupied(OccupiedEntry<'a, V>, PhantomData<V>),
    Vacant(VacantEntry<'a, V>, PhantomData<V>),
}

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

The enum is constructed from the entry method on HeteroContainer.

Variants

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

An occupied entry.

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

A vacant entry.

Implementations

impl<'a, V: 'static> Entry<'a, V>[src]

pub fn or_insert(self, default: V) -> &'a mut V[src]

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

Examples

use hetero_container::HeteroContainer;

let mut container: HeteroContainer = HeteroContainer::new();

container.entry().or_insert(3);
assert_eq!(container.get::<i32>(), Some(&3));

*container.entry().or_insert(10) *= 2;
assert_eq!(container.get::<i32>(), Some(&6));

pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V[src]

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

Examples

use hetero_container::HeteroContainer;

let mut container = HeteroContainer::new();
let s = "hoho".to_string();

container.entry::<String>().or_insert_with(|| s);

assert_eq!(container.get::<String>(), Some(&"hoho".to_string()));

pub fn key(&self) -> &TypeId[src]

Returns a reference to this entry's key.

Examples

use hetero_container::HeteroContainer;
use std::any::TypeId;

let mut container: HeteroContainer = HeteroContainer::new();
assert_eq!(container.entry::<String>().key(), &TypeId::of::<String>())

pub fn and_modify<F: FnOnce(&mut V)>(self, f: F) -> Self[src]

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

Examples

use hetero_container::HeteroContainer;

let mut container: HeteroContainer = HeteroContainer::new();

container.entry::<i32>()
    .and_modify(|e| *e += 1)
    .or_insert(42);
assert_eq!(container.get::<i32>(), Some(&42));

container.entry::<i32>()
    .and_modify(|e| *e += 1)
    .or_insert(42);
assert_eq!(container.get::<i32>(), Some(&43))

impl<'a, V: 'static + Default> Entry<'a, V>[src]

pub fn or_default(self) -> &'a mut V[src]

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

Examples

use hetero_container::HeteroContainer;

let mut container: HeteroContainer = HeteroContainer::new();
container.entry::<Option<u32>>().or_default();

assert_eq!(container.get::<Option<u32>>(), Some(&None))

Trait Implementations

impl<'a, V: Debug> Debug for Entry<'a, V>[src]

Auto Trait Implementations

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

impl<'a, V> !Send for Entry<'a, V>

impl<'a, V> !Sync for Entry<'a, V>

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.