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

An occupied entry

An vacant entry

Methods

impl<'a, K: 'a + Eq, V: 'a> Entry<'a, K, V>
[src]

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");

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);

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());

Trait Implementations

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

Formats the value using the given formatter.