Enum cache_2q::Entry
[−]
[src]
pub enum Entry<'a, K: 'a, V: 'a> { Occupied(OccupiedEntry<'a, K, V>), Vacant(VacantEntry<'a, K, V>), }
A view into a single entry in a cache, which may either be vacant or occupied.
This enum is constructed from the entry method on Cache.
Variants
Occupied(OccupiedEntry<'a, K, V>)
An occupied entry
Vacant(VacantEntry<'a, K, V>)
An vacant entry
Methods
impl<'a, K: 'a + Eq, V: 'a> Entry<'a, K, V>
[src]
fn key(&self) -> &K
Returns a reference to this entry's key.
Examples
use cache_2q::Cache; let mut cache: Cache<&str, u32> = Cache::new(8); assert_eq!(cache.entry("poneyland").key(), &"poneyland");
fn or_insert(self, default: V) -> &'a mut V
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
Examples
use cache_2q::Cache; let mut cache = Cache::new(8); { let value = cache.entry(0xFF00).or_insert(0); assert_eq!(*value, 0); } *cache.entry(0xFF00).or_insert(100) += 1; assert_eq!(*cache.get(&0xFF00).unwrap(), 1);
fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
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 cache_2q::Cache; let mut cache: Cache<&'static str, String> = Cache::new(8); cache.entry("key").or_insert_with(|| "value".to_string()); assert_eq!(cache.get(&"key").unwrap(), &"value".to_string());