Struct weak_table::PtrWeakKeyHashMap [] [src]

pub struct PtrWeakKeyHashMap<K, V, S = RandomState>(_);

A hash map with weak keys, hashed on key pointer.

When a weak pointer expires, its mapping is lazily removed.

Examples

use weak_table::PtrWeakKeyHashMap;
use std::rc::{Rc, Weak};

type Table = PtrWeakKeyHashMap<Weak<str>, usize>;

let mut map = Table::new();
let a = Rc::<str>::from("hello");
let b = Rc::<str>::from("hello");

map.insert(a.clone(), 5);

assert_eq!( map.get(&a), Some(&5) );
assert_eq!( map.get(&b), None );

map.insert(b.clone(), 7);

assert_eq!( map.get(&a), Some(&5) );
assert_eq!( map.get(&b), Some(&7) );

Methods

impl<K: WeakElement, V> PtrWeakKeyHashMap<K, V, RandomState> where
    K::Strong: Deref
[src]

Creates an empty PtrWeakKeyHashMap.

Creates an empty PtrWeakKeyHashMap with the given capacity.

impl<K: WeakElement, V, S: BuildHasher> PtrWeakKeyHashMap<K, V, S> where
    K::Strong: Deref
[src]

Creates an empty PtrWeakKeyHashMap with the given capacity and hasher.

Creates an empty PtrWeakKeyHashMap with the given capacity and hasher.

Returns a reference to the map's BuildHasher.

Returns the number of elements the map can hold without reallocating.

Removes all mappings whose keys have expired.

Reserves room for additional elements.

Shrinks the capacity to the minimum allowed to hold the current number of elements.

Returns an over-approximation of the number of elements.

Is the map known to be empty?

This could answer false for an empty map whose keys have expired but have yet to be collected.

The proportion of buckets that are used.

This is an over-approximation because of expired keys.

Gets the requested entry.

Removes all associations from the map.

Returns a reference to the value corresponding to the key.

Returns true if the map contains the specified key.

Returns a mutable reference to the value corresponding to the key.

Unconditionally inserts the value, returning the old value if already present. Does not replace the key.

Removes the entry with the given key, if it exists, and returns the value.

Removes all mappings not satisfying the given predicate.

Also removes any expired mappings.

Is this map a submap of the other, using the given value comparison.

In particular, all the keys of self must be in other and the values must compare true with value_equal.

Is self a submap of other?

Are the keys of self a subset of the keys of other?

impl<K: WeakElement, V, S> PtrWeakKeyHashMap<K, V, S> where
    K::Strong: Deref
[src]

Important traits for Iter<'a, K, V>

Gets an iterator over the keys and values.

Important traits for Keys<'a, K, V>

Gets an iterator over the keys.

Important traits for Values<'a, K, V>

Gets an iterator over the values.

Important traits for IterMut<'a, K, V>

Gets an iterator over the keys and mutable values.

Important traits for ValuesMut<'a, K, V>

Gets an iterator over the mutable values.

Important traits for Drain<'a, K, V>

Gets a draining iterator, which removes all the values but retains the storage.

Trait Implementations

impl<K, V, V1, S, S1> PartialEq<PtrWeakKeyHashMap<K, V1, S1>> for PtrWeakKeyHashMap<K, V, S> where
    K: WeakElement,
    K::Strong: Deref,
    V: PartialEq<V1>,
    S: BuildHasher,
    S1: BuildHasher
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<K: WeakElement, V: Eq, S: BuildHasher> Eq for PtrWeakKeyHashMap<K, V, S> where
    K::Strong: Deref
[src]

impl<K: WeakElement, V, S: BuildHasher + Default> Default for PtrWeakKeyHashMap<K, V, S> where
    K::Strong: Deref
[src]

Returns the "default value" for a type. Read more

impl<'a, K, V, S> Index<&'a K::Strong> for PtrWeakKeyHashMap<K, V, S> where
    K: WeakElement,
    K::Strong: Deref,
    S: BuildHasher
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl<'a, K, V, S> IndexMut<&'a K::Strong> for PtrWeakKeyHashMap<K, V, S> where
    K: WeakElement,
    K::Strong: Deref,
    S: BuildHasher
[src]

Performs the mutable indexing (container[index]) operation.

impl<K, V, S> FromIterator<(K::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
    K: WeakElement,
    K::Strong: Deref,
    S: BuildHasher + Default
[src]

Creates a value from an iterator. Read more

impl<K, V, S> Extend<(K::Strong, V)> for PtrWeakKeyHashMap<K, V, S> where
    K: WeakElement,
    K::Strong: Deref,
    S: BuildHasher
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a, K, V, S> Extend<(&'a K::Strong, &'a V)> for PtrWeakKeyHashMap<K, V, S> where
    K: 'a + WeakElement,
    K::Strong: Clone + Deref,
    V: 'a + Clone,
    S: BuildHasher
[src]

Extends a collection with the contents of an iterator. Read more

impl<K, V: Debug, S> Debug for PtrWeakKeyHashMap<K, V, S> where
    K: WeakElement,
    K::Strong: Debug
[src]

Formats the value using the given formatter. Read more

impl<K: WeakElement, V, S> IntoIterator for PtrWeakKeyHashMap<K, V, S>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, K: WeakElement, V, S> IntoIterator for &'a PtrWeakKeyHashMap<K, V, S>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, K: WeakElement, V, S> IntoIterator for &'a mut PtrWeakKeyHashMap<K, V, S>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<K: Clone, V: Clone, S: Clone> Clone for PtrWeakKeyHashMap<K, V, S>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<K, V, S> Send for PtrWeakKeyHashMap<K, V, S> where
    K: Send,
    S: Send,
    V: Send

impl<K, V, S> Sync for PtrWeakKeyHashMap<K, V, S> where
    K: Sync,
    S: Sync,
    V: Sync