pub struct HashMap<K, S>(/* private fields */);
Expand description
Polymorphic hash map
Internally this uses a HashMap
with boxed values, thus performance is
much like that of HashMap
.
Note: HashMap
’s capacity reservation API is excluded. There is no
fundamental reason for this, other than each stored value requiring an
allocation (boxing) anyway.
§Warning
Warning: values stored in the map will not have their destructor
(Drop::drop
) run when the map is destroyed. This is not currently
fixable (min_specialization
+
https://github.com/rust-lang/rust/issues/46893 may be sufficient).
Implementations§
Source§impl<K, S> HashMap<K, S>
impl<K, S> HashMap<K, S>
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Construct a new store with the given hash bulider
Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Return’s a reference to the map’s BuildHasher
Source§impl<K: Eq + Hash, S: BuildHasher> HashMap<K, S>
impl<K: Eq + Hash, S: BuildHasher> HashMap<K, S>
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Checks whether a value matching the specified key
exists
Sourcepub fn get_tagged<V: 'static>(&self, key: &TaggedKey<K, V>) -> Option<&V>
pub fn get_tagged<V: 'static>(&self, key: &TaggedKey<K, V>) -> Option<&V>
Returns a reference to the value corresponding to the key
The value’s type is inferred from the TaggedKey
.
Returns None
if no element matches tag
or if the type V
does not match the element.
Sourcepub fn get<V: 'static>(&self, key: &K) -> Option<&V>
pub fn get<V: 'static>(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the key
The value’s type must be specified explicitly.
Returns None
if no element matches key
. Panics on type mismatch.
Sourcepub fn get_tagged_mut<V: 'static>(
&mut self,
key: &TaggedKey<K, V>,
) -> Option<&mut V>
pub fn get_tagged_mut<V: 'static>( &mut self, key: &TaggedKey<K, V>, ) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key
Sourcepub fn get_mut<V: 'static>(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut<V: 'static>(&mut self, key: &K) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key
Returns None
if no element matches key
. Panics on type mismatch.
Sourcepub fn insert_boxed<V: 'static>(
&mut self,
key: K,
value: Box<V>,
) -> TaggedKey<K, V>where
K: Clone,
pub fn insert_boxed<V: 'static>(
&mut self,
key: K,
value: Box<V>,
) -> TaggedKey<K, V>where
K: Clone,
Sourcepub fn remove<V: 'static>(&mut self, key: &TaggedKey<K, V>) -> Option<V>
pub fn remove<V: 'static>(&mut self, key: &TaggedKey<K, V>) -> Option<V>
Removes and returns a value, if present
Panics on type mismatch.
Sourcepub fn remove_boxed<V: 'static>(
&mut self,
key: &TaggedKey<K, V>,
) -> Option<Box<V>>
pub fn remove_boxed<V: 'static>( &mut self, key: &TaggedKey<K, V>, ) -> Option<Box<V>>
Removes and returns a value, if present
Panics on type mismatch.