pub struct WeakMap<K, V> { /* private fields */ }
Expand description
A B-Tree map that stores weak references to values.
Implementations§
Source§impl<K, V> WeakMap<K, V>
impl<K, V> WeakMap<K, V>
Sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Gets an iterator over the entries of the map, sorted by key.
Sourcepub fn keys(&self) -> Keys<'_, K, V> ⓘ
pub fn keys(&self) -> Keys<'_, K, V> ⓘ
Gets an iterator over the keys of the map, in sorted order.
Sourcepub fn into_keys(self) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self) -> IntoKeys<K, V> ⓘ
Creates a consuming iterator visiting all the keys, in sorted order. The map cannot be used after calling this.
Sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
Gets an iterator over the values of the map, in order by key.
Sourcepub fn into_values(self) -> IntoValues<K, V> ⓘ
pub fn into_values(self) -> IntoValues<K, V> ⓘ
Creates a consuming iterator visiting all the values, in order by key. The map cannot be used after calling this.
Source§impl<K, V> WeakMap<K, V>
impl<K, V> WeakMap<K, V>
Sourcepub fn cleanup(&mut self)
pub fn cleanup(&mut self)
Cleans up the map by removing expired values.
Usually you don’t need to call this manually, as it is called automatically when the number of operations reaches a threshold.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map, excluding expired values.
This is a linear operation, as it iterates over all elements in the map.
The returned value may be less than the result of Self::raw_len
.
Sourcepub fn get<Q>(&self, key: &Q) -> Option<V::Strong>
pub fn get<Q>(&self, key: &Q) -> Option<V::Strong>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, V::Strong)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, V::Strong)>
Returns the key-value pair corresponding to the supplied key. This is potentially useful:
- for key types where non-identical keys can be considered equal;
- for getting the
&K
stored key value from a borrowed&Q
lookup key; or - for getting a reference to a key with the same lifetime as the collection.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true
if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn insert(&mut self, key: K, value: &V::Strong) -> Option<V::Strong>
pub fn insert(&mut self, key: K, value: &V::Strong) -> Option<V::Strong>
Inserts a key-value pair into the map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old
value is returned. The key is not updated, though; this matters for
types that can be ==
without being identical. See the module-level
documentation for more.
Sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V::Strong>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V::Strong>
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V::Strong)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V::Strong)>
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.