[−][src]Enum hetero_container::Entry
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
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,
V: Unpin,
impl<'a, V> !UnwindSafe for Entry<'a, V>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,