Struct hydro_lang::builder::compiled::CompiledFlow
source · pub struct CompiledFlow<'a, ID> { /* private fields */ }
Implementations§
source§impl<ID> CompiledFlow<'_, ID>
impl<ID> CompiledFlow<'_, ID>
source§impl<'a> CompiledFlow<'a, usize>
impl<'a> CompiledFlow<'a, usize>
pub fn with_dynamic_id(
+CompiledFlow in hydro_lang::builder::compiled - Rust Struct hydro_lang::builder::compiled::CompiledFlow
source · pub struct CompiledFlow<'a, ID> { /* private fields */ }
Implementations§
source§impl<ID> CompiledFlow<'_, ID>
source§impl<'a> CompiledFlow<'a, usize>
sourcepub fn with_dynamic_id(
self,
id: impl QuotedWithContext<'a, usize, ()>,
) -> CompiledFlowWithId<'a>
Trait Implementations§
source§impl<'a, Ctx> FreeVariableWithContext<Ctx> for CompiledFlow<'a, ()>
source§impl<'a, Ctx> QuotedWithContext<'a, Dfir<'a>, Ctx> for CompiledFlow<'a, ()>
source§fn splice_untyped_ctx(self, ctx: &Ctx) -> Exprwhere
diff --git a/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html b/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html
index b1e6f16f607..76b4d451b2e 100644
--- a/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html
+++ b/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
Auto Trait Implementations§
§impl Freeze for MultiNode
§impl RefUnwindSafe for MultiNode
§impl Send for MultiNode
§impl Sync for MultiNode
§impl Unpin for MultiNode
§impl UnwindSafe for MultiNode
Blanket Implementations§
source§impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html b/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
index e21bb01df64..8d3f56bc3cb 100644
--- a/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
+++ b/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
Auto Trait Implementations§
§impl Freeze for SingleNode
§impl RefUnwindSafe for SingleNode
§impl Send for SingleNode
§impl Sync for SingleNode
§impl Unpin for SingleNode
§impl UnwindSafe for SingleNode
Blanket Implementations§
source§impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
index 77b2e881651..06b63f30e5b 100644
--- a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
+++ b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
Auto Trait Implementations§
§impl Freeze for DeployRuntimeCluster
§impl !RefUnwindSafe for DeployRuntimeCluster
§impl !Send for DeployRuntimeCluster
§impl !Sync for DeployRuntimeCluster
§impl Unpin for DeployRuntimeCluster
§impl !UnwindSafe for DeployRuntimeCluster
Blanket Implementations§
source§impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
index 3e586221bb9..938a2583e0a 100644
--- a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
+++ b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
source§impl<'a> RegisterPort<'a, DeployRuntime> for DeployRuntimeNode
source§fn register(&self, _key: usize, _port: <DeployRuntime as Deploy<'_>>::Port)
source§fn raw_port(
&self,
diff --git a/doc/hydro_lang/deploy/trait.Node.html b/doc/hydro_lang/deploy/trait.Node.html
index 1ca87289ca2..61fe392c8df 100644
--- a/doc/hydro_lang/deploy/trait.Node.html
+++ b/doc/hydro_lang/deploy/trait.Node.html
@@ -10,13 +10,13 @@
&self,
env: &mut Self::InstantiateEnv,
meta: &mut Self::Meta,
- graph: DfirGraph,
+ graph: DfirGraph,
extra_stmts: Vec<Stmt>,
);
}Required Associated Types§
Required Methods§
sourcefn next_port(&self) -> Self::Port
sourcefn update_meta(&mut self, meta: &Self::Meta)
sourcefn instantiate(
&self,
env: &mut Self::InstantiateEnv,
meta: &mut Self::Meta,
- graph: DfirGraph,
+ graph: DfirGraph,
extra_stmts: Vec<Stmt>,
)
Implementors§
\ No newline at end of file
diff --git a/doc/hydro_lang/ir/enum.HydroLeaf.html b/doc/hydro_lang/ir/enum.HydroLeaf.html
index 7a92607eae8..ab8047bbefa 100644
--- a/doc/hydro_lang/ir/enum.HydroLeaf.html
+++ b/doc/hydro_lang/ir/enum.HydroLeaf.html
@@ -28,7 +28,7 @@
seen_tees: &mut SeenTees,
) -> HydroLeafsourcepub fn emit(
&self,
- graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
+ graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
built_tees: &mut HashMap<*const RefCell<HydroNode>, (Ident, usize)>,
next_stmt_id: &mut usize,
)
Trait Implementations§
Auto Trait Implementations§
§impl Freeze for HydroLeaf
§impl !RefUnwindSafe for HydroLeaf
§impl !Send for HydroLeaf
§impl !Sync for HydroLeaf
§impl Unpin for HydroLeaf
§impl !UnwindSafe for HydroLeaf
Blanket Implementations§
source§impl<T> Any for Twhere
diff --git a/doc/hydro_lang/ir/enum.HydroNode.html b/doc/hydro_lang/ir/enum.HydroNode.html
index d79b46225ac..d39cf1439a7 100644
--- a/doc/hydro_lang/ir/enum.HydroNode.html
+++ b/doc/hydro_lang/ir/enum.HydroNode.html
@@ -95,7 +95,7 @@
seen_tees: &mut SeenTees,
)sourcepub fn emit(
&self,
- graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
+ graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
built_tees: &mut HashMap<*const RefCell<HydroNode>, (Ident, usize)>,
next_stmt_id: &mut usize,
) -> (Ident, usize)
Trait Implementations§
Auto Trait Implementations§
§impl Freeze for HydroNode
§impl !RefUnwindSafe for HydroNode
§impl !Send for HydroNode
§impl !Sync for HydroNode
§impl Unpin for HydroNode
§impl !UnwindSafe for HydroNode
Blanket Implementations§
source§impl<T> Any for Twhere
diff --git a/doc/type.impl/std/collections/hash/map/struct.HashMap.js b/doc/type.impl/std/collections/hash/map/struct.HashMap.js
index 793940f2021..79f92071814 100644
--- a/doc/type.impl/std/collections/hash/map/struct.HashMap.js
+++ b/doc/type.impl/std/collections/hash/map/struct.HashMap.js
@@ -1,9 +1,9 @@
(function() {
- var type_impls = Object.fromEntries([["hydro_lang",[["","Accumulate<(K, V)>","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clone","hydro_lang::ir::SeenTees"],["","Collection","hydro_lang::ir::SeenTees"],["§impl<K, V> CollectionMut for HashMap<K, V>
","CollectionMut","hydro_lang::ir::SeenTees"],["","CollectionRef","hydro_lang::ir::SeenTees"],["","Debug","hydro_lang::ir::SeenTees"],["","Default","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more","Deserialize<'de>","hydro_lang::ir::SeenTees"],["1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (&'a K, &'a V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(&'a K, &'a V)>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (K, V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(K, V)>","hydro_lang::ir::SeenTees"],["","From<[(K, V); N]>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
","FromIterator<(K, V)>","hydro_lang::ir::SeenTees"],["","Get<&'a Q>","hydro_lang::ir::SeenTees"],["","GetKeyValue<&'a Q>","hydro_lang::ir::SeenTees"],["","GetMut<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
\nThe hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
\n1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n\n- Hash memoization
\n- Deferring the creation of an owned key until it is known to be required
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nBecause raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
\nIn particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n\n- Hash memoization
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nUnless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
\nImmutable raw entries have very limited use; you might instead want raw_entry_mut
.
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
\nThe created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
\n1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\nWarning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
\n1.0.0 · sourcepub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
\n§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
\n1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
\n1.0.0 · sourcepub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
\n1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
\nsourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
\n§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
\n1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
\n§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
\n1.9.0 · sourcepub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
\n§Panics
\nPanics if the new allocation size overflows usize
.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
\n1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
\n§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
\n1.0.0 · sourcepub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
\n1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
\n1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
\n1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
\n1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
\nsourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once.
\nReturns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
\nsourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
\nReturns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
\nFor a safe alternative see get_many_mut
.
\n§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
\n1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
\n1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
\n1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
\nIf the map did have this key present, the value is updated, and the old\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
\nsourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
\n1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
\n1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
\n",0,"hydro_lang::ir::SeenTees"],["§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
","HashMapExt","hydro_lang::ir::SeenTees"],["","Index<&Q>","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
Convert this value into a deserializer.","IntoDeserializer<'de, E>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
\n","IntoIterator","hydro_lang::ir::SeenTees"],["","Iter","hydro_lang::ir::SeenTees"],["","Keyed","hydro_lang::ir::SeenTees"],["","KeyedRef","hydro_lang::ir::SeenTees"],["","Len","hydro_lang::ir::SeenTees"],["","MapInsert","hydro_lang::ir::SeenTees"],["","MapIter","hydro_lang::ir::SeenTees"],["","MapIterMut","hydro_lang::ir::SeenTees"],["§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
§type MapValue<NewVal> = HashMap<Key, NewVal>
Output type, should be Self
but with OldVal
replaced with NewVal
.§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
Map the values into using the map_fn
.","MapMapValues","hydro_lang::ir::SeenTees"],["","PartialEq","hydro_lang::ir::SeenTees"],["","Remove<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
Serialize this value into the given Serde serializer. Read more","Serialize","hydro_lang::ir::SeenTees"],["","SimpleCollectionMut","hydro_lang::ir::SeenTees"],["","SimpleCollectionRef","hydro_lang::ir::SeenTees"],["","SimpleKeyedRef","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Eq for HashMap<K, V, S>
","Eq","hydro_lang::ir::SeenTees"],["1.36.0 · source§impl<K, V, S> UnwindSafe for HashMap<K, V, S>
","UnwindSafe","hydro_lang::ir::SeenTees"]]]]);
+ var type_impls = Object.fromEntries([["hydro_lang",[["","Accumulate<(K, V)>","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clone","hydro_lang::ir::SeenTees"],["","Collection","hydro_lang::ir::SeenTees"],["§impl<K, V> CollectionMut for HashMap<K, V>
","CollectionMut","hydro_lang::ir::SeenTees"],["","CollectionRef","hydro_lang::ir::SeenTees"],["","Debug","hydro_lang::ir::SeenTees"],["","Default","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more","Deserialize<'de>","hydro_lang::ir::SeenTees"],["1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (&'a K, &'a V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(&'a K, &'a V)>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (K, V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(K, V)>","hydro_lang::ir::SeenTees"],["","From<[(K, V); N]>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
","FromIterator<(K, V)>","hydro_lang::ir::SeenTees"],["","Get<&'a Q>","hydro_lang::ir::SeenTees"],["","GetKeyValue<&'a Q>","hydro_lang::ir::SeenTees"],["","GetMut<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
\nThe hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
\n1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n\n- Hash memoization
\n- Deferring the creation of an owned key until it is known to be required
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nBecause raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
\nIn particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n\n- Hash memoization
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nUnless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
\nImmutable raw entries have very limited use; you might instead want raw_entry_mut
.
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
\nThe created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
\n1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\nWarning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
\n1.0.0 · sourcepub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
\n§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
\n1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
\n1.0.0 · sourcepub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
\n1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
\nsourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
\n§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
\n1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
\n§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
\n1.9.0 · sourcepub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
\n§Panics
\nPanics if the new allocation size overflows usize
.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
\n1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
\n§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
\n1.0.0 · sourcepub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
\n1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
\n1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
\n1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
\n1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
\nsourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once.
\nReturns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
\nsourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
\nReturns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
\nFor a safe alternative see get_many_mut
.
\n§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
\n1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
\n1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
\n1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
\nIf the map did have this key present, the value is updated, and the old\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
\nsourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
\n1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
\n1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
\n",0,"hydro_lang::ir::SeenTees"],["§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
","HashMapExt","hydro_lang::ir::SeenTees"],["","Index<&Q>","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
Convert this value into a deserializer.","IntoDeserializer<'de, E>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
\n","IntoIterator","hydro_lang::ir::SeenTees"],["","Iter","hydro_lang::ir::SeenTees"],["","Keyed","hydro_lang::ir::SeenTees"],["","KeyedRef","hydro_lang::ir::SeenTees"],["","Len","hydro_lang::ir::SeenTees"],["","MapInsert","hydro_lang::ir::SeenTees"],["","MapIter","hydro_lang::ir::SeenTees"],["","MapIterMut","hydro_lang::ir::SeenTees"],["source§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
source§type MapValue<NewVal> = HashMap<Key, NewVal>
Output type, should be Self
but with OldVal
replaced with NewVal
.source§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
Map the values into using the map_fn
.","MapMapValues","hydro_lang::ir::SeenTees"],["","PartialEq","hydro_lang::ir::SeenTees"],["","Remove<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
Serialize this value into the given Serde serializer. Read more","Serialize","hydro_lang::ir::SeenTees"],["","SimpleCollectionMut","hydro_lang::ir::SeenTees"],["","SimpleCollectionRef","hydro_lang::ir::SeenTees"],["","SimpleKeyedRef","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Eq for HashMap<K, V, S>
","Eq","hydro_lang::ir::SeenTees"],["1.36.0 · source§impl<K, V, S> UnwindSafe for HashMap<K, V, S>
","UnwindSafe","hydro_lang::ir::SeenTees"]]]]);
if (window.register_type_impls) {
window.register_type_impls(type_impls);
} else {
window.pending_type_impls = type_impls;
}
})()
-//{"start":55,"fragment_lengths":[172101]}
\ No newline at end of file
+//{"start":55,"fragment_lengths":[172934]}
\ No newline at end of file
Struct hydro_lang::builder::compiled::CompiledFlow
source · pub struct CompiledFlow<'a, ID> { /* private fields */ }
Implementations§
source§impl<ID> CompiledFlow<'_, ID>
impl<ID> CompiledFlow<'_, ID>
source§impl<'a> CompiledFlow<'a, usize>
impl<'a> CompiledFlow<'a, usize>
pub fn with_dynamic_id( self, id: impl QuotedWithContext<'a, usize, ()>, ) -> CompiledFlowWithId<'a>
Trait Implementations§
source§impl<'a, Ctx> FreeVariableWithContext<Ctx> for CompiledFlow<'a, ()>
impl<'a, Ctx> FreeVariableWithContext<Ctx> for CompiledFlow<'a, ()>
source§impl<'a, Ctx> QuotedWithContext<'a, Dfir<'a>, Ctx> for CompiledFlow<'a, ()>
impl<'a, Ctx> QuotedWithContext<'a, Dfir<'a>, Ctx> for CompiledFlow<'a, ()>
fn splice_untyped_ctx(self, ctx: &Ctx) -> Exprwhere
diff --git a/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html b/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html
index b1e6f16f607..76b4d451b2e 100644
--- a/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html
+++ b/doc/hydro_lang/deploy/in_memory_graph/struct.MultiNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
Auto Trait Implementations§
impl Freeze for MultiNode
impl RefUnwindSafe for MultiNode
impl Send for MultiNode
impl Sync for MultiNode
impl Unpin for MultiNode
impl UnwindSafe for MultiNode
Blanket Implementations§
source§impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html b/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
index e21bb01df64..8d3f56bc3cb 100644
--- a/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
+++ b/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html b/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
index e21bb01df64..8d3f56bc3cb 100644
--- a/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
+++ b/doc/hydro_lang/deploy/in_memory_graph/struct.SingleNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
Auto Trait Implementations§
impl Freeze for SingleNode
impl RefUnwindSafe for SingleNode
impl Send for SingleNode
impl Sync for SingleNode
impl Unpin for SingleNode
impl UnwindSafe for SingleNode
Blanket Implementations§
source§impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
index 77b2e881651..06b63f30e5b 100644
--- a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
+++ b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
index 77b2e881651..06b63f30e5b 100644
--- a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
+++ b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeCluster.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
Auto Trait Implementations§
impl Freeze for DeployRuntimeCluster
impl !RefUnwindSafe for DeployRuntimeCluster
impl !Send for DeployRuntimeCluster
impl !Sync for DeployRuntimeCluster
impl Unpin for DeployRuntimeCluster
impl !UnwindSafe for DeployRuntimeCluster
Blanket Implementations§
source§impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
index 3e586221bb9..938a2583e0a 100644
--- a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
+++ b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
impl<T> Borrow<T> for Twhere
diff --git a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
index 3e586221bb9..938a2583e0a 100644
--- a/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
+++ b/doc/hydro_lang/deploy/macro_runtime/struct.DeployRuntimeNode.html
@@ -2,7 +2,7 @@
&self,
_env: &mut Self::InstantiateEnv,
_meta: &mut Self::Meta,
- _graph: DfirGraph,
+ _graph: DfirGraph,
_extra_stmts: Vec<Stmt>,
)
source§impl<'a> RegisterPort<'a, DeployRuntime> for DeployRuntimeNode
impl<'a> RegisterPort<'a, DeployRuntime> for DeployRuntimeNode
fn register(&self, _key: usize, _port: <DeployRuntime as Deploy<'_>>::Port)
fn raw_port(
&self,
diff --git a/doc/hydro_lang/deploy/trait.Node.html b/doc/hydro_lang/deploy/trait.Node.html
index 1ca87289ca2..61fe392c8df 100644
--- a/doc/hydro_lang/deploy/trait.Node.html
+++ b/doc/hydro_lang/deploy/trait.Node.html
@@ -10,13 +10,13 @@
&self,
env: &mut Self::InstantiateEnv,
meta: &mut Self::Meta,
- graph: DfirGraph,
+ graph: DfirGraph,
extra_stmts: Vec<Stmt>,
);
}Required Associated Types§
Required Methods§
sourcefn next_port(&self) -> Self::Port
sourcefn update_meta(&mut self, meta: &Self::Meta)
sourcefn instantiate(
&self,
env: &mut Self::InstantiateEnv,
meta: &mut Self::Meta,
- graph: DfirGraph,
+ graph: DfirGraph,
extra_stmts: Vec<Stmt>,
)
Implementors§
fn next_port(&self) -> Self::Port
fn update_meta(&mut self, meta: &Self::Meta)
fn instantiate( &self, env: &mut Self::InstantiateEnv, meta: &mut Self::Meta, - graph: DfirGraph, + graph: DfirGraph, extra_stmts: Vec<Stmt>, )
pub fn emit( &self, - graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>, + graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>, built_tees: &mut HashMap<*const RefCell<HydroNode>, (Ident, usize)>, next_stmt_id: &mut usize, )
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HydroLeaf
impl !RefUnwindSafe for HydroLeaf
impl !Send for HydroLeaf
impl !Sync for HydroLeaf
impl Unpin for HydroLeaf
impl !UnwindSafe for HydroLeaf
Blanket Implementations§
source§impl<T> Any for Twhere
diff --git a/doc/hydro_lang/ir/enum.HydroNode.html b/doc/hydro_lang/ir/enum.HydroNode.html
index d79b46225ac..d39cf1439a7 100644
--- a/doc/hydro_lang/ir/enum.HydroNode.html
+++ b/doc/hydro_lang/ir/enum.HydroNode.html
@@ -95,7 +95,7 @@
seen_tees: &mut SeenTees,
)sourcepub fn emit(
&self,
- graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
+ graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
built_tees: &mut HashMap<*const RefCell<HydroNode>, (Ident, usize)>,
next_stmt_id: &mut usize,
) -> (Ident, usize)
impl<T> Any for Twhere
diff --git a/doc/hydro_lang/ir/enum.HydroNode.html b/doc/hydro_lang/ir/enum.HydroNode.html
index d79b46225ac..d39cf1439a7 100644
--- a/doc/hydro_lang/ir/enum.HydroNode.html
+++ b/doc/hydro_lang/ir/enum.HydroNode.html
@@ -95,7 +95,7 @@
seen_tees: &mut SeenTees,
)sourcepub fn emit(
&self,
- graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
+ graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>,
built_tees: &mut HashMap<*const RefCell<HydroNode>, (Ident, usize)>,
next_stmt_id: &mut usize,
) -> (Ident, usize)
pub fn emit( &self, - graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>, + graph_builders: &mut BTreeMap<usize, FlatGraphBuilder>, built_tees: &mut HashMap<*const RefCell<HydroNode>, (Ident, usize)>, next_stmt_id: &mut usize, ) -> (Ident, usize)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HydroNode
impl !RefUnwindSafe for HydroNode
impl !Send for HydroNode
impl !Sync for HydroNode
impl Unpin for HydroNode
impl !UnwindSafe for HydroNode
Blanket Implementations§
source§impl<T> Any for Twhere
diff --git a/doc/type.impl/std/collections/hash/map/struct.HashMap.js b/doc/type.impl/std/collections/hash/map/struct.HashMap.js
index 793940f2021..79f92071814 100644
--- a/doc/type.impl/std/collections/hash/map/struct.HashMap.js
+++ b/doc/type.impl/std/collections/hash/map/struct.HashMap.js
@@ -1,9 +1,9 @@
(function() {
- var type_impls = Object.fromEntries([["hydro_lang",[["","Accumulate<(K, V)>","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clone","hydro_lang::ir::SeenTees"],["","Collection","hydro_lang::ir::SeenTees"],["§impl<K, V> CollectionMut for HashMap<K, V>
","CollectionMut","hydro_lang::ir::SeenTees"],["","CollectionRef","hydro_lang::ir::SeenTees"],["","Debug","hydro_lang::ir::SeenTees"],["","Default","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more","Deserialize<'de>","hydro_lang::ir::SeenTees"],["1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (&'a K, &'a V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(&'a K, &'a V)>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (K, V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(K, V)>","hydro_lang::ir::SeenTees"],["","From<[(K, V); N]>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
","FromIterator<(K, V)>","hydro_lang::ir::SeenTees"],["","Get<&'a Q>","hydro_lang::ir::SeenTees"],["","GetKeyValue<&'a Q>","hydro_lang::ir::SeenTees"],["","GetMut<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
\nThe hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
\n1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n\n- Hash memoization
\n- Deferring the creation of an owned key until it is known to be required
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nBecause raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
\nIn particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n\n- Hash memoization
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nUnless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
\nImmutable raw entries have very limited use; you might instead want raw_entry_mut
.
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
\nThe created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
\n1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\nWarning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
\n1.0.0 · sourcepub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
\n§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
\n1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
\n1.0.0 · sourcepub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
\n1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
\nsourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
\n§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
\n1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
\n§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
\n1.9.0 · sourcepub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
\n§Panics
\nPanics if the new allocation size overflows usize
.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
\n1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
\n§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
\n1.0.0 · sourcepub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
\n1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
\n1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
\n1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
\n1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
\nsourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once.
\nReturns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
\nsourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
\nReturns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
\nFor a safe alternative see get_many_mut
.
\n§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
\n1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
\n1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
\n1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
\nIf the map did have this key present, the value is updated, and the old\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
\nsourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
\n1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
\n1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
\n",0,"hydro_lang::ir::SeenTees"],["§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
","HashMapExt","hydro_lang::ir::SeenTees"],["","Index<&Q>","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
Convert this value into a deserializer.","IntoDeserializer<'de, E>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
\n","IntoIterator","hydro_lang::ir::SeenTees"],["","Iter","hydro_lang::ir::SeenTees"],["","Keyed","hydro_lang::ir::SeenTees"],["","KeyedRef","hydro_lang::ir::SeenTees"],["","Len","hydro_lang::ir::SeenTees"],["","MapInsert","hydro_lang::ir::SeenTees"],["","MapIter","hydro_lang::ir::SeenTees"],["","MapIterMut","hydro_lang::ir::SeenTees"],["§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
§type MapValue<NewVal> = HashMap<Key, NewVal>
Output type, should be Self
but with OldVal
replaced with NewVal
.§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
Map the values into using the map_fn
.","MapMapValues","hydro_lang::ir::SeenTees"],["","PartialEq","hydro_lang::ir::SeenTees"],["","Remove<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
Serialize this value into the given Serde serializer. Read more","Serialize","hydro_lang::ir::SeenTees"],["","SimpleCollectionMut","hydro_lang::ir::SeenTees"],["","SimpleCollectionRef","hydro_lang::ir::SeenTees"],["","SimpleKeyedRef","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Eq for HashMap<K, V, S>
","Eq","hydro_lang::ir::SeenTees"],["1.36.0 · source§impl<K, V, S> UnwindSafe for HashMap<K, V, S>
","UnwindSafe","hydro_lang::ir::SeenTees"]]]]);
+ var type_impls = Object.fromEntries([["hydro_lang",[["","Accumulate<(K, V)>","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clone","hydro_lang::ir::SeenTees"],["","Collection","hydro_lang::ir::SeenTees"],["§impl<K, V> CollectionMut for HashMap<K, V>
","CollectionMut","hydro_lang::ir::SeenTees"],["","CollectionRef","hydro_lang::ir::SeenTees"],["","Debug","hydro_lang::ir::SeenTees"],["","Default","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more","Deserialize<'de>","hydro_lang::ir::SeenTees"],["1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (&'a K, &'a V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(&'a K, &'a V)>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (K, V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(K, V)>","hydro_lang::ir::SeenTees"],["","From<[(K, V); N]>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
","FromIterator<(K, V)>","hydro_lang::ir::SeenTees"],["","Get<&'a Q>","hydro_lang::ir::SeenTees"],["","GetKeyValue<&'a Q>","hydro_lang::ir::SeenTees"],["","GetMut<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
\nThe hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
\n1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n\n- Hash memoization
\n- Deferring the creation of an owned key until it is known to be required
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nBecause raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
\nIn particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n\n- Hash memoization
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nUnless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
\nImmutable raw entries have very limited use; you might instead want raw_entry_mut
.
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
\nThe created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
\n1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\nWarning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
\n1.0.0 · sourcepub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
\n§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
\n1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
\n1.0.0 · sourcepub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
\n1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
\nsourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
\n§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
\n1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
\n§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
\n1.9.0 · sourcepub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
\n§Panics
\nPanics if the new allocation size overflows usize
.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
\n1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
\n§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
\n1.0.0 · sourcepub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
\n1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
\n1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
\n1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
\n1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
\nsourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once.
\nReturns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
\nsourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
\nReturns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
\nFor a safe alternative see get_many_mut
.
\n§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
\n1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
\n1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
\n1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
\nIf the map did have this key present, the value is updated, and the old\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
\nsourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
\n1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
\n1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
\n",0,"hydro_lang::ir::SeenTees"],["§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
","HashMapExt","hydro_lang::ir::SeenTees"],["","Index<&Q>","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
Convert this value into a deserializer.","IntoDeserializer<'de, E>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
\n","IntoIterator","hydro_lang::ir::SeenTees"],["","Iter","hydro_lang::ir::SeenTees"],["","Keyed","hydro_lang::ir::SeenTees"],["","KeyedRef","hydro_lang::ir::SeenTees"],["","Len","hydro_lang::ir::SeenTees"],["","MapInsert","hydro_lang::ir::SeenTees"],["","MapIter","hydro_lang::ir::SeenTees"],["","MapIterMut","hydro_lang::ir::SeenTees"],["source§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
source§type MapValue<NewVal> = HashMap<Key, NewVal>
Output type, should be Self
but with OldVal
replaced with NewVal
.source§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
Map the values into using the map_fn
.","MapMapValues","hydro_lang::ir::SeenTees"],["","PartialEq","hydro_lang::ir::SeenTees"],["","Remove<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
Serialize this value into the given Serde serializer. Read more","Serialize","hydro_lang::ir::SeenTees"],["","SimpleCollectionMut","hydro_lang::ir::SeenTees"],["","SimpleCollectionRef","hydro_lang::ir::SeenTees"],["","SimpleKeyedRef","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Eq for HashMap<K, V, S>
","Eq","hydro_lang::ir::SeenTees"],["1.36.0 · source§impl<K, V, S> UnwindSafe for HashMap<K, V, S>
","UnwindSafe","hydro_lang::ir::SeenTees"]]]]);
if (window.register_type_impls) {
window.register_type_impls(type_impls);
} else {
window.pending_type_impls = type_impls;
}
})()
-//{"start":55,"fragment_lengths":[172101]}
\ No newline at end of file
+//{"start":55,"fragment_lengths":[172934]}
\ No newline at end of file
impl<T> Any for Twhere
diff --git a/doc/type.impl/std/collections/hash/map/struct.HashMap.js b/doc/type.impl/std/collections/hash/map/struct.HashMap.js
index 793940f2021..79f92071814 100644
--- a/doc/type.impl/std/collections/hash/map/struct.HashMap.js
+++ b/doc/type.impl/std/collections/hash/map/struct.HashMap.js
@@ -1,9 +1,9 @@
(function() {
- var type_impls = Object.fromEntries([["hydro_lang",[["","Accumulate<(K, V)>","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clone","hydro_lang::ir::SeenTees"],["","Collection","hydro_lang::ir::SeenTees"],["§impl<K, V> CollectionMut for HashMap<K, V>
","CollectionMut","hydro_lang::ir::SeenTees"],["","CollectionRef","hydro_lang::ir::SeenTees"],["","Debug","hydro_lang::ir::SeenTees"],["","Default","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more","Deserialize<'de>","hydro_lang::ir::SeenTees"],["1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (&'a K, &'a V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(&'a K, &'a V)>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (K, V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(K, V)>","hydro_lang::ir::SeenTees"],["","From<[(K, V); N]>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
","FromIterator<(K, V)>","hydro_lang::ir::SeenTees"],["","Get<&'a Q>","hydro_lang::ir::SeenTees"],["","GetKeyValue<&'a Q>","hydro_lang::ir::SeenTees"],["","GetMut<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
\nThe hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
\n1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n\n- Hash memoization
\n- Deferring the creation of an owned key until it is known to be required
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nBecause raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
\nIn particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n\n- Hash memoization
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nUnless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
\nImmutable raw entries have very limited use; you might instead want raw_entry_mut
.
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
\nThe created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
\n1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\nWarning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
\n1.0.0 · sourcepub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
\n§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
\n1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
\n1.0.0 · sourcepub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
\n1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
\nsourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
\n§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
\n1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
\n§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
\n1.9.0 · sourcepub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
\n§Panics
\nPanics if the new allocation size overflows usize
.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
\n1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
\n§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
\n1.0.0 · sourcepub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
\n1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
\n1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
\n1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
\n1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
\nsourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once.
\nReturns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
\nsourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
\nReturns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
\nFor a safe alternative see get_many_mut
.
\n§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
\n1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
\n1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
\n1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
\nIf the map did have this key present, the value is updated, and the old\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
\nsourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
\n1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
\n1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
\n",0,"hydro_lang::ir::SeenTees"],["§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
","HashMapExt","hydro_lang::ir::SeenTees"],["","Index<&Q>","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
Convert this value into a deserializer.","IntoDeserializer<'de, E>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
\n","IntoIterator","hydro_lang::ir::SeenTees"],["","Iter","hydro_lang::ir::SeenTees"],["","Keyed","hydro_lang::ir::SeenTees"],["","KeyedRef","hydro_lang::ir::SeenTees"],["","Len","hydro_lang::ir::SeenTees"],["","MapInsert","hydro_lang::ir::SeenTees"],["","MapIter","hydro_lang::ir::SeenTees"],["","MapIterMut","hydro_lang::ir::SeenTees"],["§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
§type MapValue<NewVal> = HashMap<Key, NewVal>
Output type, should be Self
but with OldVal
replaced with NewVal
.§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
Map the values into using the map_fn
.","MapMapValues","hydro_lang::ir::SeenTees"],["","PartialEq","hydro_lang::ir::SeenTees"],["","Remove<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
Serialize this value into the given Serde serializer. Read more","Serialize","hydro_lang::ir::SeenTees"],["","SimpleCollectionMut","hydro_lang::ir::SeenTees"],["","SimpleCollectionRef","hydro_lang::ir::SeenTees"],["","SimpleKeyedRef","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Eq for HashMap<K, V, S>
","Eq","hydro_lang::ir::SeenTees"],["1.36.0 · source§impl<K, V, S> UnwindSafe for HashMap<K, V, S>
","UnwindSafe","hydro_lang::ir::SeenTees"]]]]);
+ var type_impls = Object.fromEntries([["hydro_lang",[["","Accumulate<(K, V)>","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clear","hydro_lang::ir::SeenTees"],["","Clone","hydro_lang::ir::SeenTees"],["","Collection","hydro_lang::ir::SeenTees"],["§impl<K, V> CollectionMut for HashMap<K, V>
","CollectionMut","hydro_lang::ir::SeenTees"],["","CollectionRef","hydro_lang::ir::SeenTees"],["","Debug","hydro_lang::ir::SeenTees"],["","Default","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more","Deserialize<'de>","hydro_lang::ir::SeenTees"],["1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (&'a K, &'a V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(&'a K, &'a V)>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read moresource§fn extend_one(&mut self, _: (K, V))
🔬This is a nightly-only experimental API. (extend_one
)Extends a collection with exactly one element.source§fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more","Extend<(K, V)>","hydro_lang::ir::SeenTees"],["","From<[(K, V); N]>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
","FromIterator<(K, V)>","hydro_lang::ir::SeenTees"],["","Get<&'a Q>","hydro_lang::ir::SeenTees"],["","GetKeyValue<&'a Q>","hydro_lang::ir::SeenTees"],["","GetMut<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
\nThe hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
\n1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n\n- Hash memoization
\n- Deferring the creation of an owned key until it is known to be required
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nBecause raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
\nIn particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n\n- Hash memoization
\n- Using a search key that doesn’t work with the Borrow trait
\n- Using custom comparison logic without newtype wrappers
\n
\nUnless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
\nImmutable raw entries have very limited use; you might instead want raw_entry_mut
.
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
\nThe created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
\n1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
\nThe hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
\nWarning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
\nThe hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
\n1.0.0 · sourcepub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
\n§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
\n1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_keys(self) -> IntoKeys<K, V>
Creates a consuming iterator visiting all the keys in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
\n§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · sourcepub fn into_values(self) -> IntoValues<K, V>
Creates a consuming iterator visiting all the values in arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
\n§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
\n§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
\n1.0.0 · sourcepub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
\n1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
\nsourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
\nIf the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
\n§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
\n1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
\n§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
\n1.9.0 · sourcepub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
\n§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
\n",0,"hydro_lang::ir::SeenTees"],["source§impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
\n§Panics
\nPanics if the new allocation size overflows usize
.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
\n1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
\n§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
\n1.0.0 · sourcepub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
\n1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
\n1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
\n1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
\n1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
\nsourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once.
\nReturns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
\nsourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
\nReturns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
\nFor a safe alternative see get_many_mut
.
\n§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
\n1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
\n1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
\n1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf the map did not have this key present, None
is returned.
\nIf the map did have this key present, the value is updated, and the old\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
\nsourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
\n1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
\n1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
\n",0,"hydro_lang::ir::SeenTees"],["§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
","HashMapExt","hydro_lang::ir::SeenTees"],["","Index<&Q>","hydro_lang::ir::SeenTees"],["source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
Convert this value into a deserializer.","IntoDeserializer<'de, E>","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
\n","IntoIterator","hydro_lang::ir::SeenTees"],["","Iter","hydro_lang::ir::SeenTees"],["","Keyed","hydro_lang::ir::SeenTees"],["","KeyedRef","hydro_lang::ir::SeenTees"],["","Len","hydro_lang::ir::SeenTees"],["","MapInsert","hydro_lang::ir::SeenTees"],["","MapIter","hydro_lang::ir::SeenTees"],["","MapIterMut","hydro_lang::ir::SeenTees"],["source§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
source§type MapValue<NewVal> = HashMap<Key, NewVal>
Output type, should be Self
but with OldVal
replaced with NewVal
.source§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
Map the values into using the map_fn
.","MapMapValues","hydro_lang::ir::SeenTees"],["","PartialEq","hydro_lang::ir::SeenTees"],["","Remove<&'a Q>","hydro_lang::ir::SeenTees"],["source§impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
Serialize this value into the given Serde serializer. Read more","Serialize","hydro_lang::ir::SeenTees"],["","SimpleCollectionMut","hydro_lang::ir::SeenTees"],["","SimpleCollectionRef","hydro_lang::ir::SeenTees"],["","SimpleKeyedRef","hydro_lang::ir::SeenTees"],["1.0.0 · source§impl<K, V, S> Eq for HashMap<K, V, S>
","Eq","hydro_lang::ir::SeenTees"],["1.36.0 · source§impl<K, V, S> UnwindSafe for HashMap<K, V, S>
","UnwindSafe","hydro_lang::ir::SeenTees"]]]]);
if (window.register_type_impls) {
window.register_type_impls(type_impls);
} else {
window.pending_type_impls = type_impls;
}
})()
-//{"start":55,"fragment_lengths":[172101]}
\ No newline at end of file
+//{"start":55,"fragment_lengths":[172934]}
\ No newline at end of file
§impl<K, V> CollectionMut for HashMap<K, V>
impl<K, V> CollectionMut for HashMap<K, V>
source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
fn extend<T>(&mut self, iter: T)
source§fn extend_one(&mut self, _: (&'a K, &'a V))
fn extend_one(&mut self, _: (&'a K, &'a V))
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
source§fn extend_one(&mut self, _: (K, V))
fn extend_one(&mut self, _: (K, V))
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
source§impl<K, V> HashMap<K, V>
impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
pub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
The hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
pub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
The hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
hash_raw_entry
)Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n- \n
- Hash memoization \n
- Deferring the creation of an owned key until it is known to be required \n
- Using a search key that doesn’t work with the Borrow trait \n
- Using custom comparison logic without newtype wrappers \n
Because raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
In particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
hash_raw_entry
)Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n- \n
- Hash memoization \n
- Using a search key that doesn’t work with the Borrow trait \n
- Using custom comparison logic without newtype wrappers \n
Unless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
Immutable raw entries have very limited use; you might instead want raw_entry_mut
.
source§impl<K, V, S> HashMap<K, V, S>
impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
pub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
The created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
The hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
The hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
Warning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
The hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
1.0.0 · sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · 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 arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · 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 arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
1.0.0 · sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
pub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
sourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
hash_extract_if
)Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
If the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
1.9.0 · sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
source§impl<K, V, S> HashMap<K, V, S>
impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
§Panics
\nPanics if the new allocation size overflows usize
.
§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
1.0.0 · sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
sourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
pub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
map_many_mut
)Attempts to get mutable references to N
values in the map at once.
Returns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
sourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
pub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
map_many_mut
)Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
Returns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
For a safe alternative see get_many_mut
.
§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &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\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf 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\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
sourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
pub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
map_try_insert
)Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
§type MapValue<NewVal> = HashMap<Key, NewVal>
type MapValue<NewVal> = HashMap<Key, NewVal>
Self
but with OldVal
replaced with NewVal
.§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
map_fn
.source§impl<K, V, H> Serialize for HashMap<K, V, H>
impl<K, V, H> Serialize for HashMap<K, V, H>
source§fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where\n S: Serializer,
impl<K, V, S> Eq for HashMap<K, V, S>
impl<K, V, S> UnwindSafe for HashMap<K, V, S>
§impl<K, V> CollectionMut for HashMap<K, V>
impl<K, V> CollectionMut for HashMap<K, V>
source§impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
impl<'de, K, V, S> Deserialize<'de> for HashMap<K, V, S>
source§fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
fn deserialize<D>(\n deserializer: D,\n) -> Result<HashMap<K, V, S>, <D as Deserializer<'de>>::Error>where\n D: Deserializer<'de>,
1.4.0 · source§impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
impl<'a, K, V, S> Extend<(&'a K, &'a V)> for HashMap<K, V, S>
source§fn extend<T>(&mut self, iter: T)
fn extend<T>(&mut self, iter: T)
source§fn extend_one(&mut self, _: (&'a K, &'a V))
fn extend_one(&mut self, _: (&'a K, &'a V))
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)1.0.0 · source§impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
impl<K, V, S> Extend<(K, V)> for HashMap<K, V, S>
Inserts all new key-values from the iterator and replaces values with existing\nkeys with new values returned from the iterator.
\nsource§fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T)where\n T: IntoIterator<Item = (K, V)>,
source§fn extend_one(&mut self, _: (K, V))
fn extend_one(&mut self, _: (K, V))
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)1.0.0 · source§impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
impl<K, V, S> FromIterator<(K, V)> for HashMap<K, V, S>
source§impl<K, V> HashMap<K, V>
impl<K, V> HashMap<K, V>
1.0.0 · sourcepub fn new() -> HashMap<K, V>
pub fn new() -> HashMap<K, V>
Creates an empty HashMap
.
The hash map is initially created with a capacity of 0, so it will not allocate until it\nis first inserted into.
\n§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();
1.0.0 · sourcepub fn with_capacity(capacity: usize) -> HashMap<K, V>
pub fn with_capacity(capacity: usize) -> HashMap<K, V>
Creates an empty HashMap
with at least the specified capacity.
The hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
source§impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
impl<K, V, S> HashMap<K, V, S>where\n S: BuildHasher,
sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
hash_raw_entry
)Creates a raw entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched. After this, insertions into a vacant entry\nstill require an owned key to be provided.
\nRaw entries are useful for such exotic situations as:
\n- \n
- Hash memoization \n
- Deferring the creation of an owned key until it is known to be required \n
- Using a search key that doesn’t work with the Borrow trait \n
- Using custom comparison logic without newtype wrappers \n
Because raw entries provide much more low-level control, it’s much easier\nto put the HashMap into an inconsistent state which, while memory-safe,\nwill cause the map to produce seemingly random results. Higher-level and\nmore foolproof APIs like entry
should be preferred when possible.
In particular, the hash used to initialize the raw entry must still be\nconsistent with the hash of the key that is ultimately stored in the entry.\nThis is because implementations of HashMap may need to recompute hashes\nwhen resizing, at which point only the keys are available.
\nRaw entries give mutable access to the keys. This must not be used\nto modify how the key would compare or hash, as the map will not re-evaluate\nwhere the key should go, meaning the keys may become “lost” if their\nlocation does not reflect their state. For instance, if you change a key\nso that the map now contains keys which compare equal, search may start\nacting erratically, with two keys randomly masking each other. Implementations\nare free to assume this doesn’t happen (within the limits of memory-safety).
\nsourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
🔬This is a nightly-only experimental API. (hash_raw_entry
)
pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
hash_raw_entry
)Creates a raw immutable entry builder for the HashMap.
\nRaw entries provide the lowest level of control for searching and\nmanipulating a map. They must be manually initialized with a hash and\nthen manually searched.
\nThis is useful for
\n- \n
- Hash memoization \n
- Using a search key that doesn’t work with the Borrow trait \n
- Using custom comparison logic without newtype wrappers \n
Unless you are in such a situation, higher-level and more foolproof APIs like\nget
should be preferred.
Immutable raw entries have very limited use; you might instead want raw_entry_mut
.
source§impl<K, V, S> HashMap<K, V, S>
impl<K, V, S> HashMap<K, V, S>
1.7.0 (const: unstable) · sourcepub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
pub fn with_hasher(hash_builder: S) -> HashMap<K, V, S>
Creates an empty HashMap
which will use the given hash builder to hash\nkeys.
The created map has the default initial capacity.
\nWarning: hash_builder
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
The hash_builder
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_hasher(s);\nmap.insert(1, 2);
1.7.0 · sourcepub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S>
Creates an empty HashMap
with at least the specified capacity, using\nhasher
to hash the keys.
The hash map will be able to hold at least capacity
elements without\nreallocating. This method is allowed to allocate for more elements than\ncapacity
. If capacity
is 0, the hash map will not allocate.
Warning: hasher
is normally randomly generated, and\nis designed to allow HashMaps to be resistant to attacks that\ncause many collisions and very poor performance. Setting it\nmanually using this function can expose a DoS attack vector.
The hasher
passed should implement the BuildHasher
trait for\nthe HashMap to be useful, see its documentation for details.
§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet s = RandomState::new();\nlet mut map = HashMap::with_capacity_and_hasher(10, s);\nmap.insert(1, 2);
1.0.0 · sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
\nThis number is a lower bound; the HashMap<K, V>
might be able to hold\nmore, but is guaranteed to be able to hold at least this many.
§Examples
\nuse std::collections::HashMap;\nlet map: HashMap<i32, i32> = HashMap::with_capacity(100);\nassert!(map.capacity() >= 100);
1.0.0 · sourcepub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
An iterator visiting all keys in arbitrary order.\nThe iterator element type is &'a K
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor key in map.keys() {\n println!(\"{key}\");\n}
§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · 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 arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is K
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<&str> = map.into_keys().collect();\n// The `IntoKeys` iterator produces keys in arbitrary order, so the\n// keys must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [\"a\", \"b\", \"c\"]);
§Performance
\nIn the current implementation, iterating over keys takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
An iterator visiting all values in arbitrary order.\nThe iterator element type is &'a V
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values() {\n println!(\"{val}\");\n}
§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.10.0 · sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
An iterator visiting all values mutably in arbitrary order.\nThe iterator element type is &'a mut V
.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor val in map.values_mut() {\n *val = *val + 10;\n}\n\nfor val in map.values() {\n println!(\"{val}\");\n}
§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.54.0 · 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 arbitrary order.\nThe map cannot be used after calling this.\nThe iterator element type is V
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nlet mut vec: Vec<i32> = map.into_values().collect();\n// The `IntoValues` iterator produces values in arbitrary order, so\n// the values must be sorted to test them against a sorted array.\nvec.sort_unstable();\nassert_eq!(vec, [1, 2, 3]);
§Performance
\nIn the current implementation, iterating over values takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order.\nThe iterator element type is (&'a K, &'a V)
.
§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\nfor (key, val) in map.iter() {\n println!(\"key: {key} val: {val}\");\n}
§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
An iterator visiting all key-value pairs in arbitrary order,\nwith mutable references to the values.\nThe iterator element type is (&'a K, &'a mut V)
.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Update all values\nfor (_, val) in map.iter_mut() {\n *val *= 2;\n}\n\nfor (key, val) in &map {\n println!(\"key: {key} val: {val}\");\n}
§Performance
\nIn the current implementation, iterating over map takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert_eq!(a.len(), 0);\na.insert(1, \"a\");\nassert_eq!(a.len(), 1);
1.0.0 · sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the map contains no elements.
§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\nassert!(a.is_empty());\na.insert(1, \"a\");\nassert!(!a.is_empty());
1.6.0 · sourcepub fn drain(&mut self) -> Drain<'_, K, V>
pub fn drain(&mut self) -> Drain<'_, K, V>
Clears the map, returning all key-value pairs as an iterator. Keeps the\nallocated memory for reuse.
\nIf the returned iterator is dropped before being fully consumed, it\ndrops the remaining key-value pairs. The returned iterator keeps a\nmutable borrow on the map to optimize its implementation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.insert(2, \"b\");\n\nfor (k, v) in a.drain().take(1) {\n assert!(k == 1 || k == 2);\n assert!(v == \"a\" || v == \"b\");\n}\n\nassert!(a.is_empty());
sourcepub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
🔬This is a nightly-only experimental API. (hash_extract_if
)
pub fn extract_if<F>(&mut self, pred: F) -> ExtractIf<'_, K, V, F>
hash_extract_if
)Creates an iterator which uses a closure to determine if an element should be removed.
\nIf the closure returns true, the element is removed from the map and yielded.\nIf the closure returns false, or panics, the element remains in the map and will not be\nyielded.
\nNote that extract_if
lets you mutate every value in the filter closure, regardless of\nwhether you choose to keep or remove it.
If the returned ExtractIf
is not exhausted, e.g. because it is dropped without iterating\nor the iteration short-circuits, then the remaining elements will be retained.\nUse retain
with a negated predicate if you do not need the returned iterator.
§Examples
\nSplitting a map into even and odd keys, reusing the original map:
\n\n#![feature(hash_extract_if)]\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x)).collect();\nlet extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % 2 == 0).collect();\n\nlet mut evens = extracted.keys().copied().collect::<Vec<_>>();\nlet mut odds = map.keys().copied().collect::<Vec<_>>();\nevens.sort();\nodds.sort();\n\nassert_eq!(evens, vec![0, 2, 4, 6]);\nassert_eq!(odds, vec![1, 3, 5, 7]);
1.18.0 · sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the elements specified by the predicate.
\nIn other words, remove all pairs (k, v)
for which f(&k, &mut v)
returns false
.\nThe elements are visited in unsorted (and unspecified) order.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();\nmap.retain(|&k, _| k % 2 == 0);\nassert_eq!(map.len(), 4);
§Performance
\nIn the current implementation, this operation takes O(capacity) time\ninstead of O(len) because it internally visits empty buckets too.
\n1.0.0 · sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory\nfor reuse.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut a = HashMap::new();\na.insert(1, \"a\");\na.clear();\nassert!(a.is_empty());
1.9.0 · sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
§Examples
\nuse std::collections::HashMap;\nuse std::hash::RandomState;\n\nlet hasher = RandomState::new();\nlet map: HashMap<i32, i32> = HashMap::with_hasher(hasher);\nlet hasher: &RandomState = map.hasher();
source§impl<K, V, S> HashMap<K, V, S>
impl<K, V, S> HashMap<K, V, S>
1.0.0 · sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling reserve
,\ncapacity will be greater than or equal to self.len() + additional
.\nDoes nothing if capacity is already sufficient.
§Panics
\nPanics if the new allocation size overflows usize
.
§Examples
\nuse std::collections::HashMap;\nlet mut map: HashMap<&str, i32> = HashMap::new();\nmap.reserve(10);
1.57.0 · sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Tries to reserve capacity for at least additional
more elements to be inserted\nin the HashMap
. The collection may reserve more space to speculatively\navoid frequent reallocations. After calling try_reserve
,\ncapacity will be greater than or equal to self.len() + additional
if\nit returns Ok(())
.\nDoes nothing if capacity is already sufficient.
§Errors
\nIf the capacity overflows, or the allocator reports a failure, then an error\nis returned.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<&str, isize> = HashMap::new();\nmap.try_reserve(10).expect(\"why is the test harness OOMing on a handful of bytes?\");
1.0.0 · sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the map as much as possible. It will drop\ndown as much as possible while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to_fit();\nassert!(map.capacity() >= 2);
1.56.0 · sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the map with a lower limit. It will drop\ndown no lower than the supplied limit while maintaining the internal rules\nand possibly leaving some space in accordance with the resize policy.
\nIf the current capacity is less than the lower limit, this is a no-op.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut map: HashMap<i32, i32> = HashMap::with_capacity(100);\nmap.insert(1, 2);\nmap.insert(3, 4);\nassert!(map.capacity() >= 100);\nmap.shrink_to(10);\nassert!(map.capacity() >= 10);\nmap.shrink_to(0);\nassert!(map.capacity() >= 2);
1.0.0 · sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Gets the given key’s corresponding entry in the map for in-place manipulation.
\n§Examples
\nuse std::collections::HashMap;\n\nlet mut letters = HashMap::new();\n\nfor ch in \"a short treatise on fungi\".chars() {\n letters.entry(ch).and_modify(|counter| *counter += 1).or_insert(1);\n}\n\nassert_eq!(letters[&'s'], 2);\nassert_eq!(letters[&'t'], 3);\nassert_eq!(letters[&'u'], 1);\nassert_eq!(letters.get(&'y'), None);
1.0.0 · sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get(&1), Some(&\"a\"));\nassert_eq!(map.get(&2), None);
1.40.0 · sourcepub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
\nThe supplied key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.get_key_value(&1), Some((&1, &\"a\")));\nassert_eq!(map.get_key_value(&2), None);
sourcepub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
pub fn get_many_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
map_many_mut
)Attempts to get mutable references to N
values in the map at once.
Returns an array of length N
with the results of each query. For soundness, at most one\nmutable reference will be returned to any value. None
will be returned if any of the\nkeys are duplicates or missing.
§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);\n\n// Duplicate keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Athenæum\",\n]);\nassert_eq!(got, None);
sourcepub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
🔬This is a nightly-only experimental API. (map_many_mut
)
pub unsafe fn get_many_unchecked_mut<Q, const N: usize>(\n &mut self,\n ks: [&Q; N],\n) -> Option<[&mut V; N]>
map_many_mut
)Attempts to get mutable references to N
values in the map at once, without validating that\nthe values are unique.
Returns an array of length N
with the results of each query. None
will be returned if\nany of the keys are missing.
For a safe alternative see get_many_mut
.
§Safety
\nCalling this method with overlapping keys is undefined behavior even if the resulting\nreferences are not used.
\n§Examples
\n#![feature(map_many_mut)]\nuse std::collections::HashMap;\n\nlet mut libraries = HashMap::new();\nlibraries.insert(\"Bodleian Library\".to_string(), 1602);\nlibraries.insert(\"Athenæum\".to_string(), 1807);\nlibraries.insert(\"Herzogin-Anna-Amalia-Bibliothek\".to_string(), 1691);\nlibraries.insert(\"Library of Congress\".to_string(), 1800);\n\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"Library of Congress\",\n]);\nassert_eq!(\n got,\n Some([\n &mut 1807,\n &mut 1800,\n ]),\n);\n\n// Missing keys result in None\nlet got = libraries.get_many_mut([\n \"Athenæum\",\n \"New York Public Library\",\n]);\nassert_eq!(got, None);
1.0.0 · sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &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\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.contains_key(&1), true);\nassert_eq!(map.contains_key(&2), false);
1.0.0 · sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nif let Some(x) = map.get_mut(&1) {\n *x = \"b\";\n}\nassert_eq!(map[&1], \"b\");
1.0.0 · sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
\nIf 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\nvalue is returned. The key is not updated, though; this matters for\ntypes that can be ==
without being identical. See the module-level\ndocumentation for more.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.insert(37, \"a\"), None);\nassert_eq!(map.is_empty(), false);\n\nmap.insert(37, \"b\");\nassert_eq!(map.insert(37, \"c\"), Some(\"b\"));\nassert_eq!(map[&37], \"c\");
sourcepub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
🔬This is a nightly-only experimental API. (map_try_insert
)
pub fn try_insert(\n &mut self,\n key: K,\n value: V,\n) -> Result<&mut V, OccupiedError<'_, K, V>>
map_try_insert
)Tries to insert a key-value pair into the map, and returns\na mutable reference to the value in the entry.
\nIf the map already had this key present, nothing is updated, and\nan error containing the occupied entry and the value is returned.
\n§Examples
\nBasic usage:
\n\n#![feature(map_try_insert)]\n\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nassert_eq!(map.try_insert(37, \"a\").unwrap(), &\"a\");\n\nlet err = map.try_insert(37, \"b\").unwrap_err();\nassert_eq!(err.entry.key(), &37);\nassert_eq!(err.entry.get(), &\"a\");\nassert_eq!(err.value, \"b\");
1.0.0 · sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the value at the key if the key\nwas previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove(&1), Some(\"a\"));\nassert_eq!(map.remove(&1), None);
1.27.0 · sourcepub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Removes a key from the map, returning the stored key and value if the\nkey was previously in the map.
\nThe key may be any borrowed form of the map’s key type, but\nHash
and Eq
on the borrowed form must match those for\nthe key type.
§Examples
\nuse std::collections::HashMap;\n\nlet mut map = HashMap::new();\nmap.insert(1, \"a\");\nassert_eq!(map.remove_entry(&1), Some((1, \"a\")));\nassert_eq!(map.remove(&1), None);
§impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
impl<K, V, S> HashMapExt for HashMap<K, V, S>where\n S: BuildHasher + Default,
source§impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
impl<'de, K, V, S, E> IntoDeserializer<'de, E> for HashMap<K, V, S>where\n K: IntoDeserializer<'de, E> + Eq + Hash,\n V: IntoDeserializer<'de, E>,\n S: BuildHasher,\n E: Error,
source§type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
type Deserializer = MapDeserializer<'de, <HashMap<K, V, S> as IntoIterator>::IntoIter, E>
source§fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
fn into_deserializer(\n self,\n) -> <HashMap<K, V, S> as IntoDeserializer<'de, E>>::Deserializer
1.0.0 · source§impl<K, V, S> IntoIterator for HashMap<K, V, S>
impl<K, V, S> IntoIterator for HashMap<K, V, S>
source§fn into_iter(self) -> IntoIter<K, V>
fn into_iter(self) -> IntoIter<K, V>
Creates a consuming iterator, that is, one that moves each key-value\npair out of the map in arbitrary order. The map cannot be used after\ncalling this.
\n§Examples
\nuse std::collections::HashMap;\n\nlet map = HashMap::from([\n (\"a\", 1),\n (\"b\", 2),\n (\"c\", 3),\n]);\n\n// Not possible with .iter()\nlet vec: Vec<(&str, i32)> = map.into_iter().collect();
source§impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
impl<Key, OldVal> MapMapValues<OldVal> for HashMap<Key, OldVal>
source§type MapValue<NewVal> = HashMap<Key, NewVal>
type MapValue<NewVal> = HashMap<Key, NewVal>
Self
but with OldVal
replaced with NewVal
.source§fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
fn map_values<NewVal, MapFn>(\n self,\n map_fn: MapFn,\n) -> <HashMap<Key, OldVal> as MapMapValues<OldVal>>::MapValue<NewVal>where\n MapFn: FnMut(OldVal) -> NewVal,
map_fn
.