mirror of
https://github.com/OMGeeky/google-apis-rs.git
synced 2026-01-29 05:12:45 +01:00
625 lines
134 KiB
HTML
625 lines
134 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `HashMap` struct in crate `hashbrown`."><meta name="keywords" content="rust, rustlang, rust-lang, HashMap"><title>hashbrown::HashMap - Rust</title><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../ayu.css" disabled ><script id="default-settings"></script><script src="../storage.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../favicon.svg">
|
||
<link rel="alternate icon" type="image/png" href="../favicon-16x16.png">
|
||
<link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><body class="rustdoc struct"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">☰</div><a href='../hashbrown/index.html'><div class='logo-container rust-logo'><img src='../rust-logo.png' alt='logo'></div></a><p class="location">Struct HashMap</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#implementations">Methods</a><div class="sidebar-links"><a href="#method.capacity">capacity</a><a href="#method.clear">clear</a><a href="#method.contains_key">contains_key</a><a href="#method.drain">drain</a><a href="#method.drain_filter">drain_filter</a><a href="#method.entry">entry</a><a href="#method.get">get</a><a href="#method.get_key_value">get_key_value</a><a href="#method.get_key_value_mut">get_key_value_mut</a><a href="#method.get_mut">get_mut</a><a href="#method.hasher">hasher</a><a href="#method.insert">insert</a><a href="#method.is_empty">is_empty</a><a href="#method.iter">iter</a><a href="#method.iter_mut">iter_mut</a><a href="#method.keys">keys</a><a href="#method.len">len</a><a href="#method.raw_entry">raw_entry</a><a href="#method.raw_entry_mut">raw_entry_mut</a><a href="#method.remove">remove</a><a href="#method.remove_entry">remove_entry</a><a href="#method.reserve">reserve</a><a href="#method.retain">retain</a><a href="#method.shrink_to">shrink_to</a><a href="#method.shrink_to_fit">shrink_to_fit</a><a href="#method.try_reserve">try_reserve</a><a href="#method.values">values</a><a href="#method.values_mut">values_mut</a><a href="#method.with_capacity_and_hasher">with_capacity_and_hasher</a><a href="#method.with_hasher">with_hasher</a></div><a class="sidebar-title" href="#trait-implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Clone">Clone</a><a href="#impl-Debug">Debug</a><a href="#impl-Default">Default</a><a href="#impl-Eq">Eq</a><a href="#impl-Extend%3C(%26%27a%20K%2C%20%26%27a%20V)%3E">Extend<(&'a K, &'a V)></a><a href="#impl-Extend%3C(K%2C%20V)%3E">Extend<(K, V)></a><a href="#impl-FromIterator%3C(K%2C%20V)%3E">FromIterator<(K, V)></a><a href="#impl-Index%3C%26%27_%20Q%3E">Index<&'_ Q></a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-PartialEq%3CHashMap%3CK%2C%20V%2C%20S%3E%3E">PartialEq<HashMap<K, V, S>></a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a><a href="#impl-Unpin">Unpin</a></div><a class="sidebar-title" href="#blanket-implementations">Blanket Implementations</a><div class="sidebar-links"><a href="#impl-Any">Any</a><a href="#impl-Borrow%3CT%3E">Borrow<T></a><a href="#impl-BorrowMut%3CT%3E">BorrowMut<T></a><a href="#impl-From%3CT%3E">From<T></a><a href="#impl-Into%3CU%3E">Into<U></a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-TryFrom%3CU%3E">TryFrom<U></a><a href="#impl-TryInto%3CU%3E">TryInto<U></a></div></div><p class="location"><a href="index.html">hashbrown</a></p><div id="sidebar-vars" data-name="HashMap" data-ty="struct" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||
<a id="settings-menu" href="../settings.html"><img src="../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Struct <a href="index.html">hashbrown</a>::<wbr><a class="struct" href="">HashMap</a></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../src/hashbrown/map.rs.html#188-191" title="goto source code">[src]</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class="rust struct">pub struct HashMap<K, V, S = <a class="enum" href="../hashbrown/hash_map/enum.DefaultHashBuilder.html" title="enum hashbrown::hash_map::DefaultHashBuilder">DefaultHashBuilder</a>> { /* fields omitted */ }</pre></div><div class="docblock"><p>A hash map implemented with quadratic probing and SIMD lookup.</p>
|
||
<p>The default hashing algorithm is currently <a href="https://crates.io/crates/ahash"><code>AHash</code></a>, though this is
|
||
subject to change at any point in the future. This hash function is very
|
||
fast for all types of keys, but this algorithm will typically <em>not</em> protect
|
||
against attacks such as HashDoS.</p>
|
||
<p>The hashing algorithm can be replaced on a per-<code>HashMap</code> basis using the
|
||
<a href="#method.default"><code>default</code></a>, <a href="#method.with_hasher"><code>with_hasher</code></a>, and <a href="#method.with_capacity_and_hasher"><code>with_capacity_and_hasher</code></a> methods. Many
|
||
alternative algorithms are available on crates.io, such as the <a href="https://crates.io/crates/fnv"><code>fnv</code></a> crate.</p>
|
||
<p>It is required that the keys implement the <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> and <a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> traits, although
|
||
this can frequently be achieved by using <code>#[derive(PartialEq, Eq, Hash)]</code>.
|
||
If you implement these yourself, it is important that the following
|
||
property holds:</p>
|
||
<pre><code class="language-text">k1 == k2 -> hash(k1) == hash(k2)
|
||
</code></pre>
|
||
<p>In other words, if two keys are equal, their hashes must be equal.</p>
|
||
<p>It is a logic error for a key to be modified in such a way that the key's
|
||
hash, as determined by the <a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> trait, or its equality, as determined by
|
||
the <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> trait, changes while it is in the map. This is normally only
|
||
possible through <a href="https://doc.rust-lang.org/std/cell/struct.Cell.html"><code>Cell</code></a>, <a href="https://doc.rust-lang.org/std/cell/struct.RefCell.html"><code>RefCell</code></a>, global state, I/O, or unsafe code.</p>
|
||
<p>It is also a logic error for the <a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> implementation of a key to panic.
|
||
This is generally only possible if the trait is implemented manually. If a
|
||
panic does occur then the contents of the <code>HashMap</code> may become corrupted and
|
||
some items may be dropped from the table.</p>
|
||
<h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="comment">// Type inference lets us omit an explicit type signature (which</span>
|
||
<span class="comment">// would be `HashMap<String, String>` in this example).</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">book_reviews</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
|
||
<span class="comment">// Review some books.</span>
|
||
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
|
||
<span class="string">"Adventures of Huckleberry Finn"</span>.<span class="ident">to_string</span>(),
|
||
<span class="string">"My favorite book."</span>.<span class="ident">to_string</span>(),
|
||
);
|
||
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
|
||
<span class="string">"Grimms' Fairy Tales"</span>.<span class="ident">to_string</span>(),
|
||
<span class="string">"Masterpiece."</span>.<span class="ident">to_string</span>(),
|
||
);
|
||
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
|
||
<span class="string">"Pride and Prejudice"</span>.<span class="ident">to_string</span>(),
|
||
<span class="string">"Very enjoyable."</span>.<span class="ident">to_string</span>(),
|
||
);
|
||
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
|
||
<span class="string">"The Adventures of Sherlock Holmes"</span>.<span class="ident">to_string</span>(),
|
||
<span class="string">"Eye lyked it alot."</span>.<span class="ident">to_string</span>(),
|
||
);
|
||
|
||
<span class="comment">// Check for a specific one.</span>
|
||
<span class="comment">// When collections store owned values (String), they can still be</span>
|
||
<span class="comment">// queried using references (&str).</span>
|
||
<span class="kw">if</span> <span class="op">!</span><span class="ident">book_reviews</span>.<span class="ident">contains_key</span>(<span class="string">"Les Misérables"</span>) {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"We've got {} reviews, but Les Misérables ain't one."</span>,
|
||
<span class="ident">book_reviews</span>.<span class="ident">len</span>());
|
||
}
|
||
|
||
<span class="comment">// oops, this review has a lot of spelling mistakes, let's delete it.</span>
|
||
<span class="ident">book_reviews</span>.<span class="ident">remove</span>(<span class="string">"The Adventures of Sherlock Holmes"</span>);
|
||
|
||
<span class="comment">// Look up the values associated with some keys.</span>
|
||
<span class="kw">let</span> <span class="ident">to_find</span> <span class="op">=</span> [<span class="string">"Pride and Prejudice"</span>, <span class="string">"Alice's Adventure in Wonderland"</span>];
|
||
<span class="kw">for</span> <span class="kw-2">&</span><span class="ident">book</span> <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">to_find</span> {
|
||
<span class="kw">match</span> <span class="ident">book_reviews</span>.<span class="ident">get</span>(<span class="ident">book</span>) {
|
||
<span class="prelude-val">Some</span>(<span class="ident">review</span>) <span class="op">=</span><span class="op">></span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}: {}"</span>, <span class="ident">book</span>, <span class="ident">review</span>),
|
||
<span class="prelude-val">None</span> <span class="op">=</span><span class="op">></span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">"{} is unreviewed."</span>, <span class="ident">book</span>)
|
||
}
|
||
}
|
||
|
||
<span class="comment">// Look up the value for a key (will panic if the key is not found).</span>
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Review for Jane: {}"</span>, <span class="ident">book_reviews</span>[<span class="string">"Pride and Prejudice"</span>]);
|
||
|
||
<span class="comment">// Iterate over everything.</span>
|
||
<span class="kw">for</span> (<span class="ident">book</span>, <span class="ident">review</span>) <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">book_reviews</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}: \"{}\""</span>, <span class="ident">book</span>, <span class="ident">review</span>);
|
||
}</pre></div>
|
||
<p><code>HashMap</code> also implements an <a href="#method.entry"><code>Entry API</code></a>, which allows
|
||
for more complex methods of getting, setting, updating and removing keys and
|
||
their values:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="comment">// type inference lets us omit an explicit type signature (which</span>
|
||
<span class="comment">// would be `HashMap<&str, u8>` in this example).</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">player_stats</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
|
||
<span class="kw">fn</span> <span class="ident">random_stat_buff</span>() <span class="op">-</span><span class="op">></span> <span class="ident">u8</span> {
|
||
<span class="comment">// could actually return some random value here - let's just return</span>
|
||
<span class="comment">// some fixed value for now</span>
|
||
<span class="number">42</span>
|
||
}
|
||
|
||
<span class="comment">// insert a key only if it doesn't already exist</span>
|
||
<span class="ident">player_stats</span>.<span class="ident">entry</span>(<span class="string">"health"</span>).<span class="ident">or_insert</span>(<span class="number">100</span>);
|
||
|
||
<span class="comment">// insert a key using a function that provides a new value only if it</span>
|
||
<span class="comment">// doesn't already exist</span>
|
||
<span class="ident">player_stats</span>.<span class="ident">entry</span>(<span class="string">"defence"</span>).<span class="ident">or_insert_with</span>(<span class="ident">random_stat_buff</span>);
|
||
|
||
<span class="comment">// update a key, guarding against the key possibly not being set</span>
|
||
<span class="kw">let</span> <span class="ident">stat</span> <span class="op">=</span> <span class="ident">player_stats</span>.<span class="ident">entry</span>(<span class="string">"attack"</span>).<span class="ident">or_insert</span>(<span class="number">100</span>);
|
||
<span class="kw-2">*</span><span class="ident">stat</span> <span class="op">+</span><span class="op">=</span> <span class="ident">random_stat_buff</span>();</pre></div>
|
||
<p>The easiest way to use <code>HashMap</code> with a custom key type is to derive <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> and <a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a>.
|
||
We must also derive <a href="https://doc.rust-lang.org/std/cmp/trait.PartialEq.html"><code>PartialEq</code></a>.</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Hash</span>, <span class="ident">Eq</span>, <span class="ident">PartialEq</span>, <span class="ident">Debug</span>)]</span>
|
||
<span class="kw">struct</span> <span class="ident">Viking</span> {
|
||
<span class="ident">name</span>: <span class="ident">String</span>,
|
||
<span class="ident">country</span>: <span class="ident">String</span>,
|
||
}
|
||
|
||
<span class="kw">impl</span> <span class="ident">Viking</span> {
|
||
<span class="doccomment">/// Creates a new Viking.</span>
|
||
<span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">name</span>: <span class="kw-2">&</span><span class="ident">str</span>, <span class="ident">country</span>: <span class="kw-2">&</span><span class="ident">str</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Viking</span> {
|
||
<span class="ident">Viking</span> { <span class="ident">name</span>: <span class="ident">name</span>.<span class="ident">to_string</span>(), <span class="ident">country</span>: <span class="ident">country</span>.<span class="ident">to_string</span>() }
|
||
}
|
||
}
|
||
|
||
<span class="comment">// Use a HashMap to store the vikings' health points.</span>
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vikings</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
|
||
<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span>::<span class="ident">new</span>(<span class="string">"Einar"</span>, <span class="string">"Norway"</span>), <span class="number">25</span>);
|
||
<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span>::<span class="ident">new</span>(<span class="string">"Olaf"</span>, <span class="string">"Denmark"</span>), <span class="number">24</span>);
|
||
<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span>::<span class="ident">new</span>(<span class="string">"Harald"</span>, <span class="string">"Iceland"</span>), <span class="number">12</span>);
|
||
|
||
<span class="comment">// Use derived implementation to print the status of the vikings.</span>
|
||
<span class="kw">for</span> (<span class="ident">viking</span>, <span class="ident">health</span>) <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">vikings</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{:?} has {} hp"</span>, <span class="ident">viking</span>, <span class="ident">health</span>);
|
||
}</pre></div>
|
||
<p>A <code>HashMap</code> with fixed list of elements can be initialized from an array:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">timber_resources</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> [(<span class="string">"Norway"</span>, <span class="number">100</span>), (<span class="string">"Denmark"</span>, <span class="number">50</span>), (<span class="string">"Iceland"</span>, <span class="number">10</span>)]
|
||
.<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
|
||
<span class="comment">// use the values stored in map</span></pre></div>
|
||
</div><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><h3 id="impl" class="impl"><code class="in-band">impl<K, V, S> <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S></code><a href="#impl" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#251-640" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.with_hasher" class="method"><code>pub const fn <a href="#method.with_hasher" class="fnname">with_hasher</a>(hash_builder: S) -> Self</code><a class="srclink" href="../src/hashbrown/map.rs.html#278-283" title="goto source code">[src]</a></h4><div class="docblock"><p>Creates an empty <code>HashMap</code> which will use the given hash builder to hash
|
||
keys.</p>
|
||
<p>The created map has the default initial capacity.</p>
|
||
<p>Warning: <code>hash_builder</code> is normally randomly generated, and
|
||
is designed to allow HashMaps to be resistant to attacks that
|
||
cause many collisions and very poor performance. Setting it
|
||
manually using this function can expose a DoS attack vector.</p>
|
||
<p>The <code>hash_builder</code> passed should implement the <a href="../../std/hash/trait.BuildHasher.html"><code>BuildHasher</code></a> trait for
|
||
the HashMap to be useful, see its documentation for details.</p>
|
||
<h1 id="examples-1" class="section-header"><a href="#examples-1">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">hash_map</span>::<span class="ident">DefaultHashBuilder</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">DefaultHashBuilder</span>::<span class="ident">default</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_hasher</span>(<span class="ident">s</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="number">2</span>);</pre></div>
|
||
</div><h4 id="method.with_capacity_and_hasher" class="method"><code>pub fn <a href="#method.with_capacity_and_hasher" class="fnname">with_capacity_and_hasher</a>(capacity: usize, hash_builder: S) -> Self</code><a class="srclink" href="../src/hashbrown/map.rs.html#312-317" title="goto source code">[src]</a></h4><div class="docblock"><p>Creates an empty <code>HashMap</code> with the specified capacity, using <code>hash_builder</code>
|
||
to hash the keys.</p>
|
||
<p>The hash map will be able to hold at least <code>capacity</code> elements without
|
||
reallocating. If <code>capacity</code> is 0, the hash map will not allocate.</p>
|
||
<p>Warning: <code>hash_builder</code> is normally randomly generated, and
|
||
is designed to allow HashMaps to be resistant to attacks that
|
||
cause many collisions and very poor performance. Setting it
|
||
manually using this function can expose a DoS attack vector.</p>
|
||
<p>The <code>hash_builder</code> passed should implement the <a href="../../std/hash/trait.BuildHasher.html"><code>BuildHasher</code></a> trait for
|
||
the HashMap to be useful, see its documentation for details.</p>
|
||
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">hash_map</span>::<span class="ident">DefaultHashBuilder</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">DefaultHashBuilder</span>::<span class="ident">default</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_capacity_and_hasher</span>(<span class="number">10</span>, <span class="ident">s</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="number">2</span>);</pre></div>
|
||
</div><h4 id="method.hasher" class="method"><code>pub fn <a href="#method.hasher" class="fnname">hasher</a>(&self) -> &S</code><a class="srclink" href="../src/hashbrown/map.rs.html#334-336" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns a reference to the map's <a href="https://doc.rust-lang.org/std/hash/trait.BuildHasher.html"><code>BuildHasher</code></a>.</p>
|
||
<h1 id="examples-3" class="section-header"><a href="#examples-3">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">hash_map</span>::<span class="ident">DefaultHashBuilder</span>;
|
||
|
||
<span class="kw">let</span> <span class="ident">hasher</span> <span class="op">=</span> <span class="ident">DefaultHashBuilder</span>::<span class="ident">default</span>();
|
||
<span class="kw">let</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_hasher</span>(<span class="ident">hasher</span>);
|
||
<span class="kw">let</span> <span class="ident">hasher</span>: <span class="kw-2">&</span><span class="ident">DefaultHashBuilder</span> <span class="op">=</span> <span class="ident">map</span>.<span class="ident">hasher</span>();</pre></div>
|
||
</div><h4 id="method.capacity" class="method"><code>pub fn <a href="#method.capacity" class="fnname">capacity</a>(&self) -> usize</code><a class="srclink" href="../src/hashbrown/map.rs.html#351-353" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns the number of elements the map can hold without reallocating.</p>
|
||
<p>This number is a lower bound; the <code>HashMap<K, V></code> might be able to hold
|
||
more, but is guaranteed to be able to hold at least this many.</p>
|
||
<h1 id="examples-4" class="section-header"><a href="#examples-4">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
<span class="kw">let</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">100</span>);</pre></div>
|
||
</div><h4 id="method.keys" class="method"><code>pub fn <a href="#method.keys" class="fnname">keys</a>(&self) -> <a class="struct" href="../hashbrown/hash_map/struct.Keys.html" title="struct hashbrown::hash_map::Keys">Keys</a><'_, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.Keys.html" title="struct hashbrown::hash_map::Keys">Keys</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.Keys.html" title="struct hashbrown::hash_map::Keys">Keys</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = &'a K;</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#373-375" title="goto source code">[src]</a></h4><div class="docblock"><p>An iterator visiting all keys in arbitrary order.
|
||
The iterator element type is <code>&'a K</code>.</p>
|
||
<h1 id="examples-5" class="section-header"><a href="#examples-5">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"a"</span>, <span class="number">1</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"b"</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"c"</span>, <span class="number">3</span>);
|
||
|
||
<span class="kw">for</span> <span class="ident">key</span> <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">keys</span>() {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">key</span>);
|
||
}</pre></div>
|
||
</div><h4 id="method.values" class="method"><code>pub fn <a href="#method.values" class="fnname">values</a>(&self) -> <a class="struct" href="../hashbrown/hash_map/struct.Values.html" title="struct hashbrown::hash_map::Values">Values</a><'_, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.Values.html" title="struct hashbrown::hash_map::Values">Values</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.Values.html" title="struct hashbrown::hash_map::Values">Values</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = &'a V;</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#395-397" title="goto source code">[src]</a></h4><div class="docblock"><p>An iterator visiting all values in arbitrary order.
|
||
The iterator element type is <code>&'a V</code>.</p>
|
||
<h1 id="examples-6" class="section-header"><a href="#examples-6">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"a"</span>, <span class="number">1</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"b"</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"c"</span>, <span class="number">3</span>);
|
||
|
||
<span class="kw">for</span> <span class="ident">val</span> <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">values</span>() {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">val</span>);
|
||
}</pre></div>
|
||
</div><h4 id="method.values_mut" class="method"><code>pub fn <a href="#method.values_mut" class="fnname">values_mut</a>(&mut self) -> <a class="struct" href="../hashbrown/hash_map/struct.ValuesMut.html" title="struct hashbrown::hash_map::ValuesMut">ValuesMut</a><'_, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.ValuesMut.html" title="struct hashbrown::hash_map::ValuesMut">ValuesMut</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.ValuesMut.html" title="struct hashbrown::hash_map::ValuesMut">ValuesMut</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = &'a mut V;</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#422-426" title="goto source code">[src]</a></h4><div class="docblock"><p>An iterator visiting all values mutably in arbitrary order.
|
||
The iterator element type is <code>&'a mut V</code>.</p>
|
||
<h1 id="examples-7" class="section-header"><a href="#examples-7">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"a"</span>, <span class="number">1</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"b"</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"c"</span>, <span class="number">3</span>);
|
||
|
||
<span class="kw">for</span> <span class="ident">val</span> <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">values_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">val</span> <span class="op">=</span> <span class="kw-2">*</span><span class="ident">val</span> <span class="op">+</span> <span class="number">10</span>;
|
||
}
|
||
|
||
<span class="kw">for</span> <span class="ident">val</span> <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">values</span>() {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"{}"</span>, <span class="ident">val</span>);
|
||
}</pre></div>
|
||
</div><h4 id="method.iter" class="method"><code>pub fn <a href="#method.iter" class="fnname">iter</a>(&self) -> <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'_, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (&'a K, &'a V);</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#446-454" title="goto source code">[src]</a></h4><div class="docblock"><p>An iterator visiting all key-value pairs in arbitrary order.
|
||
The iterator element type is <code>(&'a K, &'a V)</code>.</p>
|
||
<h1 id="examples-8" class="section-header"><a href="#examples-8">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"a"</span>, <span class="number">1</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"b"</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"c"</span>, <span class="number">3</span>);
|
||
|
||
<span class="kw">for</span> (<span class="ident">key</span>, <span class="ident">val</span>) <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">iter</span>() {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"key: {} val: {}"</span>, <span class="ident">key</span>, <span class="ident">val</span>);
|
||
}</pre></div>
|
||
</div><h4 id="method.iter_mut" class="method"><code>pub fn <a href="#method.iter_mut" class="fnname">iter_mut</a>(&mut self) -> <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'_, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (&'a K, &'a mut V);</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#480-488" title="goto source code">[src]</a></h4><div class="docblock"><p>An iterator visiting all key-value pairs in arbitrary order,
|
||
with mutable references to the values.
|
||
The iterator element type is <code>(&'a K, &'a mut V)</code>.</p>
|
||
<h1 id="examples-9" class="section-header"><a href="#examples-9">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"a"</span>, <span class="number">1</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"b"</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"c"</span>, <span class="number">3</span>);
|
||
|
||
<span class="comment">// Update all values</span>
|
||
<span class="kw">for</span> (<span class="kw">_</span>, <span class="ident">val</span>) <span class="kw">in</span> <span class="ident">map</span>.<span class="ident">iter_mut</span>() {
|
||
<span class="kw-2">*</span><span class="ident">val</span> <span class="kw-2">*</span><span class="op">=</span> <span class="number">2</span>;
|
||
}
|
||
|
||
<span class="kw">for</span> (<span class="ident">key</span>, <span class="ident">val</span>) <span class="kw">in</span> <span class="kw-2">&</span><span class="ident">map</span> {
|
||
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"key: {} val: {}"</span>, <span class="ident">key</span>, <span class="ident">val</span>);
|
||
}</pre></div>
|
||
</div><h4 id="method.len" class="method"><code>pub fn <a href="#method.len" class="fnname">len</a>(&self) -> usize</code><a class="srclink" href="../src/hashbrown/map.rs.html#509-511" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns the number of elements in the map.</p>
|
||
<h1 id="examples-10" class="section-header"><a href="#examples-10">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">0</span>);
|
||
<span class="ident">a</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">len</span>(), <span class="number">1</span>);</pre></div>
|
||
</div><h4 id="method.is_empty" class="method"><code>pub fn <a href="#method.is_empty" class="fnname">is_empty</a>(&self) -> bool</code><a class="srclink" href="../src/hashbrown/map.rs.html#526-528" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns <code>true</code> if the map contains no elements.</p>
|
||
<h1 id="examples-11" class="section-header"><a href="#examples-11">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_empty</span>());
|
||
<span class="ident">a</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">a</span>.<span class="ident">is_empty</span>());</pre></div>
|
||
</div><h4 id="method.drain" class="method"><code>pub fn <a href="#method.drain" class="fnname">drain</a>(&mut self) -> <a class="struct" href="../hashbrown/hash_map/struct.Drain.html" title="struct hashbrown::hash_map::Drain">Drain</a><'_, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.Drain.html" title="struct hashbrown::hash_map::Drain">Drain</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.Drain.html" title="struct hashbrown::hash_map::Drain">Drain</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (K, V);</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#550-554" title="goto source code">[src]</a></h4><div class="docblock"><p>Clears the map, returning all key-value pairs as an iterator. Keeps the
|
||
allocated memory for reuse.</p>
|
||
<h1 id="examples-12" class="section-header"><a href="#examples-12">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">a</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="ident">a</span>.<span class="ident">insert</span>(<span class="number">2</span>, <span class="string">"b"</span>);
|
||
|
||
<span class="kw">for</span> (<span class="ident">k</span>, <span class="ident">v</span>) <span class="kw">in</span> <span class="ident">a</span>.<span class="ident">drain</span>().<span class="ident">take</span>(<span class="number">1</span>) {
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">k</span> <span class="op">=</span><span class="op">=</span> <span class="number">1</span> <span class="op">|</span><span class="op">|</span> <span class="ident">k</span> <span class="op">=</span><span class="op">=</span> <span class="number">2</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span> <span class="op">=</span><span class="op">=</span> <span class="string">"a"</span> <span class="op">|</span><span class="op">|</span> <span class="ident">v</span> <span class="op">=</span><span class="op">=</span> <span class="string">"b"</span>);
|
||
}
|
||
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_empty</span>());</pre></div>
|
||
</div><h4 id="method.retain" class="method"><code>pub fn <a href="#method.retain" class="fnname">retain</a><F>(&mut self, f: F) <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&K, &mut V) -> bool, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#569-582" title="goto source code">[src]</a></h4><div class="docblock"><p>Retains only the elements specified by the predicate.</p>
|
||
<p>In other words, remove all pairs <code>(k, v)</code> such that <code>f(&k,&mut v)</code> returns <code>false</code>.</p>
|
||
<h1 id="examples-13" class="section-header"><a href="#examples-13">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">8</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span>(<span class="ident">x</span>, <span class="ident">x</span><span class="kw-2">*</span><span class="number">10</span>)).<span class="ident">collect</span>();
|
||
<span class="ident">map</span>.<span class="ident">retain</span>(<span class="op">|</span><span class="kw-2">&</span><span class="ident">k</span>, <span class="kw">_</span><span class="op">|</span> <span class="ident">k</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">len</span>(), <span class="number">4</span>);</pre></div>
|
||
</div><h4 id="method.drain_filter" class="method"><code>pub fn <a href="#method.drain_filter" class="fnname">drain_filter</a><F>(&mut self, f: F) -> <a class="struct" href="../hashbrown/hash_map/struct.DrainFilter.html" title="struct hashbrown::hash_map::DrainFilter">DrainFilter</a><'_, K, V, F><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.DrainFilter.html" title="struct hashbrown::hash_map::DrainFilter">DrainFilter</a><'_, K, V, F></h3><code class="content"><span class="where fmt-newline">impl<K, V, F> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.DrainFilter.html" title="struct hashbrown::hash_map::DrainFilter">DrainFilter</a><'_, K, V, F> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&K, &mut V) -> bool, </span></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (K, V);</span></code></span></div></span></span> <span class="where fmt-newline">where<br> F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(&K, &mut V) -> bool, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#610-621" title="goto source code">[src]</a></h4><div class="docblock"><p>Drains elements which are true under the given predicate,
|
||
and returns an iterator over the removed items.</p>
|
||
<p>In other words, move all pairs <code>(k, v)</code> such that <code>f(&k,&mut v)</code> returns <code>true</code> out
|
||
into another iterator.</p>
|
||
<p>When the returned DrainedFilter is dropped, any remaining elements that satisfy
|
||
the predicate are dropped from the table.</p>
|
||
<h1 id="examples-14" class="section-header"><a href="#examples-14">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> (<span class="number">0</span>..<span class="number">8</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">x</span><span class="op">|</span> (<span class="ident">x</span>, <span class="ident">x</span>)).<span class="ident">collect</span>();
|
||
<span class="kw">let</span> <span class="ident">drained</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">map</span>.<span class="ident">drain_filter</span>(<span class="op">|</span><span class="ident">k</span>, <span class="ident">_v</span><span class="op">|</span> <span class="ident">k</span> <span class="op">%</span> <span class="number">2</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span>).<span class="ident">collect</span>();
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">evens</span> <span class="op">=</span> <span class="ident">drained</span>.<span class="ident">keys</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>::<span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span><span class="op">></span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">odds</span> <span class="op">=</span> <span class="ident">map</span>.<span class="ident">keys</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>::<span class="op"><</span><span class="ident">Vec</span><span class="op"><</span><span class="kw">_</span><span class="op">></span><span class="op">></span>();
|
||
<span class="ident">evens</span>.<span class="ident">sort</span>();
|
||
<span class="ident">odds</span>.<span class="ident">sort</span>();
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">evens</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>]);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">odds</span>, <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>]);</pre></div>
|
||
</div><h4 id="method.clear" class="method"><code>pub fn <a href="#method.clear" class="fnname">clear</a>(&mut self)</code><a class="srclink" href="../src/hashbrown/map.rs.html#637-639" title="goto source code">[src]</a></h4><div class="docblock"><p>Clears the map, removing all key-value pairs. Keeps the allocated memory
|
||
for reuse.</p>
|
||
<h1 id="examples-15" class="section-header"><a href="#examples-15">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">a</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">a</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="ident">a</span>.<span class="ident">clear</span>();
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_empty</span>());</pre></div>
|
||
</div></div><h3 id="impl-1" class="impl"><code class="in-band">impl<K, V, S> <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>, </span></code><a href="#impl-1" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#642-1066" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.reserve" class="method"><code>pub fn <a href="#method.reserve" class="fnname">reserve</a>(&mut self, additional: usize)</code><a class="srclink" href="../src/hashbrown/map.rs.html#665-669" title="goto source code">[src]</a></h4><div class="docblock"><p>Reserves capacity for at least <code>additional</code> more elements to be inserted
|
||
in the <code>HashMap</code>. The collection may reserve more space to avoid
|
||
frequent reallocations.</p>
|
||
<h1 id="panics" class="section-header"><a href="#panics">Panics</a></h1>
|
||
<p>Panics if the new allocation size overflows <a href="https://doc.rust-lang.org/std/primitive.usize.html"><code>usize</code></a>.</p>
|
||
<h1 id="examples-16" class="section-header"><a href="#examples-16">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">reserve</span>(<span class="number">10</span>);</pre></div>
|
||
</div><h4 id="method.try_reserve" class="method"><code>pub fn <a href="#method.try_reserve" class="fnname">try_reserve</a>(&mut self, additional: usize) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><(), <a class="enum" href="../hashbrown/enum.TryReserveError.html" title="enum hashbrown::TryReserveError">TryReserveError</a>></code><a class="srclink" href="../src/hashbrown/map.rs.html#688-692" title="goto source code">[src]</a></h4><div class="docblock"><p>Tries to reserve capacity for at least <code>additional</code> more elements to be inserted
|
||
in the given <code>HashMap<K,V></code>. The collection may reserve more space to avoid
|
||
frequent reallocations.</p>
|
||
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
|
||
<p>If the capacity overflows, or the allocator reports a failure, then an error
|
||
is returned.</p>
|
||
<h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="kw-2">&</span><span class="ident">str</span>, <span class="ident">isize</span><span class="op">></span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">try_reserve</span>(<span class="number">10</span>).<span class="ident">expect</span>(<span class="string">"why is the test harness OOMing on 10 bytes?"</span>);</pre></div>
|
||
</div><h4 id="method.shrink_to_fit" class="method"><code>pub fn <a href="#method.shrink_to_fit" class="fnname">shrink_to_fit</a>(&mut self)</code><a class="srclink" href="../src/hashbrown/map.rs.html#711-714" title="goto source code">[src]</a></h4><div class="docblock"><p>Shrinks the capacity of the map as much as possible. It will drop
|
||
down as much as possible while maintaining the internal rules
|
||
and possibly leaving some space in accordance with the resize policy.</p>
|
||
<h1 id="examples-18" class="section-header"><a href="#examples-18">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">3</span>, <span class="number">4</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">100</span>);
|
||
<span class="ident">map</span>.<span class="ident">shrink_to_fit</span>();
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">2</span>);</pre></div>
|
||
</div><h4 id="method.shrink_to" class="method"><code>pub fn <a href="#method.shrink_to" class="fnname">shrink_to</a>(&mut self, min_capacity: usize)</code><a class="srclink" href="../src/hashbrown/map.rs.html#740-744" title="goto source code">[src]</a></h4><div class="docblock"><p>Shrinks the capacity of the map with a lower limit. It will drop
|
||
down no lower than the supplied limit while maintaining the internal rules
|
||
and possibly leaving some space in accordance with the resize policy.</p>
|
||
<p>This function does nothing if the current capacity is smaller than the
|
||
supplied minimum capacity.</p>
|
||
<h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op"><</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">3</span>, <span class="number">4</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">100</span>);
|
||
<span class="ident">map</span>.<span class="ident">shrink_to</span>(<span class="number">10</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">10</span>);
|
||
<span class="ident">map</span>.<span class="ident">shrink_to</span>(<span class="number">0</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">shrink_to</span>(<span class="number">10</span>);
|
||
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">capacity</span>() <span class="op">></span><span class="op">=</span> <span class="number">2</span>);</pre></div>
|
||
</div><h4 id="method.entry" class="method"><code>pub fn <a href="#method.entry" class="fnname">entry</a>(&mut self, key: K) -> <a class="enum" href="../hashbrown/hash_map/enum.Entry.html" title="enum hashbrown::hash_map::Entry">Entry</a><'_, K, V, S></code><a class="srclink" href="../src/hashbrown/map.rs.html#766-782" title="goto source code">[src]</a></h4><div class="docblock"><p>Gets the given key's corresponding entry in the map for in-place manipulation.</p>
|
||
<h1 id="examples-20" class="section-header"><a href="#examples-20">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">letters</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
|
||
<span class="kw">for</span> <span class="ident">ch</span> <span class="kw">in</span> <span class="string">"a short treatise on fungi"</span>.<span class="ident">chars</span>() {
|
||
<span class="kw">let</span> <span class="ident">counter</span> <span class="op">=</span> <span class="ident">letters</span>.<span class="ident">entry</span>(<span class="ident">ch</span>).<span class="ident">or_insert</span>(<span class="number">0</span>);
|
||
<span class="kw-2">*</span><span class="ident">counter</span> <span class="op">+</span><span class="op">=</span> <span class="number">1</span>;
|
||
}
|
||
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">letters</span>[<span class="kw-2">&</span><span class="string">'s'</span>], <span class="number">2</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">letters</span>[<span class="kw-2">&</span><span class="string">'t'</span>], <span class="number">3</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">letters</span>[<span class="kw-2">&</span><span class="string">'u'</span>], <span class="number">1</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">letters</span>.<span class="ident">get</span>(<span class="kw-2">&</span><span class="string">'y'</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id="method.get" class="method"><code>pub fn <a href="#method.get" class="fnname">get</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&self, k: &Q) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&V> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#804-814" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns a reference to the value corresponding to the key.</p>
|
||
<p>The key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-21" class="section-header"><a href="#examples-21">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">get</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="string">"a"</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">get</span>(<span class="kw-2">&</span><span class="number">2</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id="method.get_key_value" class="method"><code>pub fn <a href="#method.get_key_value" class="fnname">get_key_value</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&self, k: &Q) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(&K, &V)> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#836-846" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns the key-value pair corresponding to the supplied key.</p>
|
||
<p>The supplied key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-22" class="section-header"><a href="#examples-22">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">get_key_value</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="string">"a"</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">get_key_value</span>(<span class="kw-2">&</span><span class="number">2</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id="method.get_key_value_mut" class="method"><code>pub fn <a href="#method.get_key_value_mut" class="fnname">get_key_value_mut</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&mut self, k: &Q) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(&K, &mut V)> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#882-892" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns the key-value pair corresponding to the supplied key, with a mutable reference to value.</p>
|
||
<p>The supplied key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-23" class="section-header"><a href="#examples-23">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="kw">let</span> (<span class="ident">k</span>, <span class="ident">v</span>) <span class="op">=</span> <span class="ident">map</span>.<span class="ident">get_key_value_mut</span>(<span class="kw-2">&</span><span class="number">1</span>).<span class="ident">unwrap</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">k</span>, <span class="kw-2">&</span><span class="number">1</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="string">"a"</span>);
|
||
<span class="kw-2">*</span><span class="ident">v</span> <span class="op">=</span> <span class="string">"b"</span>;
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">get_key_value_mut</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="kw-2">&</span><span class="number">1</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="string">"b"</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">get_key_value_mut</span>(<span class="kw-2">&</span><span class="number">2</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id="method.contains_key" class="method"><code>pub fn <a href="#method.contains_key" class="fnname">contains_key</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&self, k: &Q) -> bool <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#914-920" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns <code>true</code> if the map contains a value for the specified key.</p>
|
||
<p>The key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-24" class="section-header"><a href="#examples-24">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">contains_key</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="bool-val">true</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">contains_key</span>(<span class="kw-2">&</span><span class="number">2</span>), <span class="bool-val">false</span>);</pre></div>
|
||
</div><h4 id="method.get_mut" class="method"><code>pub fn <a href="#method.get_mut" class="fnname">get_mut</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&mut self, k: &Q) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut V> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#944-954" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns a mutable reference to the value corresponding to the key.</p>
|
||
<p>The key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-25" class="section-header"><a href="#examples-25">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">x</span>) <span class="op">=</span> <span class="ident">map</span>.<span class="ident">get_mut</span>(<span class="kw-2">&</span><span class="number">1</span>) {
|
||
<span class="kw-2">*</span><span class="ident">x</span> <span class="op">=</span> <span class="string">"b"</span>;
|
||
}
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>[<span class="kw-2">&</span><span class="number">1</span>], <span class="string">"b"</span>);</pre></div>
|
||
</div><h4 id="method.insert" class="method"><code>pub fn <a href="#method.insert" class="fnname">insert</a>(&mut self, k: K, v: V) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><V></code><a class="srclink" href="../src/hashbrown/map.rs.html#992-1002" title="goto source code">[src]</a></h4><div class="docblock"><p>Inserts a key-value pair into the map.</p>
|
||
<p>If the map did not have this key present, <a href="https://doc.rust-lang.org/std/option/enum.Option.html#variant.None"><code>None</code></a> is returned.</p>
|
||
<p>If the map did have this key present, the value is updated, and the old
|
||
value is returned. The key is not updated, though; this matters for
|
||
types that can be <code>==</code> without being identical. See the <a href="index.html#insert-and-complex-keys">module-level
|
||
documentation</a> for more.</p>
|
||
<h1 id="examples-26" class="section-header"><a href="#examples-26">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">37</span>, <span class="string">"a"</span>), <span class="prelude-val">None</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">is_empty</span>(), <span class="bool-val">false</span>);
|
||
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">37</span>, <span class="string">"b"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">37</span>, <span class="string">"c"</span>), <span class="prelude-val">Some</span>(<span class="string">"b"</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>[<span class="kw-2">&</span><span class="number">37</span>], <span class="string">"c"</span>);</pre></div>
|
||
</div><h4 id="method.remove" class="method"><code>pub fn <a href="#method.remove" class="fnname">remove</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&mut self, k: &Q) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><V> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#1025-1035" title="goto source code">[src]</a></h4><div class="docblock"><p>Removes a key from the map, returning the value at the key if the key
|
||
was previously in the map.</p>
|
||
<p>The key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-27" class="section-header"><a href="#examples-27">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">remove</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="string">"a"</span>));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">remove</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
</div><h4 id="method.remove_entry" class="method"><code>pub fn <a href="#method.remove_entry" class="fnname">remove_entry</a><Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>>(&mut self, k: &Q) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(K, V)> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>, </span></code><a class="srclink" href="../src/hashbrown/map.rs.html#1058-1065" title="goto source code">[src]</a></h4><div class="docblock"><p>Removes a key from the map, returning the stored key and value if the
|
||
key was previously in the map.</p>
|
||
<p>The key may be any borrowed form of the map's key type, but
|
||
<a href="https://doc.rust-lang.org/std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/std/cmp/trait.Eq.html"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h1 id="examples-28" class="section-header"><a href="#examples-28">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">remove_entry</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">"a"</span>)));
|
||
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>.<span class="ident">remove</span>(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">None</span>);</pre></div>
|
||
</div></div><h3 id="impl-2" class="impl"><code class="in-band">impl<K, V, S> <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S></code><a href="#impl-2" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#1068-1124" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.raw_entry_mut" class="method"><code>pub fn <a href="#method.raw_entry_mut" class="fnname">raw_entry_mut</a>(&mut self) -> <a class="struct" href="../hashbrown/hash_map/struct.RawEntryBuilderMut.html" title="struct hashbrown::hash_map::RawEntryBuilderMut">RawEntryBuilderMut</a><'_, K, V, S></code><a class="srclink" href="../src/hashbrown/map.rs.html#1101-1103" title="goto source code">[src]</a></h4><div class="docblock"><p>Creates a raw entry builder for the HashMap.</p>
|
||
<p>Raw entries provide the lowest level of control for searching and
|
||
manipulating a map. They must be manually initialized with a hash and
|
||
then manually searched. After this, insertions into a vacant entry
|
||
still require an owned key to be provided.</p>
|
||
<p>Raw entries are useful for such exotic situations as:</p>
|
||
<ul>
|
||
<li>Hash memoization</li>
|
||
<li>Deferring the creation of an owned key until it is known to be required</li>
|
||
<li>Using a search key that doesn't work with the Borrow trait</li>
|
||
<li>Using custom comparison logic without newtype wrappers</li>
|
||
</ul>
|
||
<p>Because raw entries provide much more low-level control, it's much easier
|
||
to put the HashMap into an inconsistent state which, while memory-safe,
|
||
will cause the map to produce seemingly random results. Higher-level and
|
||
more foolproof APIs like <code>entry</code> should be preferred when possible.</p>
|
||
<p>In particular, the hash used to initialized the raw entry must still be
|
||
consistent with the hash of the key that is ultimately stored in the entry.
|
||
This is because implementations of HashMap may need to recompute hashes
|
||
when resizing, at which point only the keys are available.</p>
|
||
<p>Raw entries give mutable access to the keys. This must not be used
|
||
to modify how the key would compare or hash, as the map will not re-evaluate
|
||
where the key should go, meaning the keys may become "lost" if their
|
||
location does not reflect their state. For instance, if you change a key
|
||
so that the map now contains keys which compare equal, search may start
|
||
acting erratically, with two keys randomly masking each other. Implementations
|
||
are free to assume this doesn't happen (within the limits of memory-safety).</p>
|
||
</div><h4 id="method.raw_entry" class="method"><code>pub fn <a href="#method.raw_entry" class="fnname">raw_entry</a>(&self) -> <a class="struct" href="../hashbrown/hash_map/struct.RawEntryBuilder.html" title="struct hashbrown::hash_map::RawEntryBuilder">RawEntryBuilder</a><'_, K, V, S></code><a class="srclink" href="../src/hashbrown/map.rs.html#1121-1123" title="goto source code">[src]</a></h4><div class="docblock"><p>Creates a raw immutable entry builder for the HashMap.</p>
|
||
<p>Raw entries provide the lowest level of control for searching and
|
||
manipulating a map. They must be manually initialized with a hash and
|
||
then manually searched.</p>
|
||
<p>This is useful for</p>
|
||
<ul>
|
||
<li>Hash memoization</li>
|
||
<li>Using a search key that doesn't work with the Borrow trait</li>
|
||
<li>Using custom comparison logic without newtype wrappers</li>
|
||
</ul>
|
||
<p>Unless you are in such a situation, higher-level and more foolproof APIs like
|
||
<code>get</code> should be preferred.</p>
|
||
<p>Immutable raw entries have very limited use; you might instead want <code>raw_entry_mut</code>.</p>
|
||
</div></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><h3 id="impl-Clone" class="impl"><code class="in-band">impl<K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S></code><a href="#impl-Clone" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#193-207" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.clone" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone" class="fnname">clone</a>(&self) -> Self</code><a class="srclink" href="../src/hashbrown/map.rs.html#194-199" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
|
||
</div><h4 id="method.clone_from" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from" class="fnname">clone_from</a>(&mut self, source: &Self)</code><a class="srclink" href="../src/hashbrown/map.rs.html#201-206" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from">Read more</a></p>
|
||
</div></div><h3 id="impl-Debug" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>, </span></code><a href="#impl-Debug" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#1150-1158" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.fmt" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code><a class="srclink" href="../src/hashbrown/map.rs.html#1155-1157" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
|
||
</div></div><h3 id="impl-Default" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>, </span></code><a href="#impl-Default" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#1160-1169" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.default" class="method"><code>fn <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default" class="fnname">default</a>() -> Self</code><a class="srclink" href="../src/hashbrown/map.rs.html#1166-1168" title="goto source code">[src]</a></h4><div class="docblock"><p>Creates an empty <code>HashMap<K, V, S></code>, with the <code>Default</code> value for the hasher.</p>
|
||
</div></div><h3 id="impl-Eq" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>, </span></code><a href="#impl-Eq" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#1142-1148" title="goto source code">[src]</a></h3><div class="impl-items"></div><h3 id="impl-Extend%3C(%26%27a%20K%2C%20%26%27a%20V)%3E" class="impl"><code class="in-band">impl<'a, K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><(&'a K, &'a V)> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>, </span></code><a href="#impl-Extend%3C(%26%27a%20K%2C%20%26%27a%20V)%3E" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#3065-3087" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.extend-1" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#tymethod.extend" class="fnname">extend</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = (&'a K, &'a V)>>(&mut self, iter: T)</code><a class="srclink" href="../src/hashbrown/map.rs.html#3072-3074" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Extends a collection with the contents of an iterator. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#tymethod.extend">Read more</a></p>
|
||
</div><h4 id="method.extend_one-1" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#method.extend_one" class="fnname">extend_one</a>(&mut self, item: A)</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/iter/traits/collect.rs.html#340" title="goto source code">[src]</a></h4><div class="item-info hidden"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>extend_one</code>)</div></div><div class='docblock hidden'><p>Extends a collection with exactly one element.</p>
|
||
</div><h4 id="method.extend_reserve-1" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#method.extend_reserve" class="fnname">extend_reserve</a>(&mut self, additional: usize)</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/iter/traits/collect.rs.html#348" title="goto source code">[src]</a></h4><div class="item-info hidden"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>extend_one</code>)</div></div><div class='docblock hidden'><p>Reserves capacity in a collection for the given number of additional elements. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#method.extend_reserve">Read more</a></p>
|
||
</div></div><h3 id="impl-Extend%3C(K%2C%20V)%3E" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html" title="trait core::iter::traits::collect::Extend">Extend</a><(K, V)> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>, </span></code><a href="#impl-Extend%3C(K%2C%20V)%3E" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#3020-3063" title="goto source code">[src]</a></h3><div class="docblock"><p>Inserts all new key-values from the iterator and replaces values with existing
|
||
keys with new values returned from the iterator.</p>
|
||
</div><div class="impl-items"><h4 id="method.extend" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#tymethod.extend" class="fnname">extend</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = (K, V)>>(&mut self, iter: T)</code><a class="srclink" href="../src/hashbrown/map.rs.html#3026-3041" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Extends a collection with the contents of an iterator. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#tymethod.extend">Read more</a></p>
|
||
</div><h4 id="method.extend_one" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#method.extend_one" class="fnname">extend_one</a>(&mut self, item: A)</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/iter/traits/collect.rs.html#340" title="goto source code">[src]</a></h4><div class="item-info hidden"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>extend_one</code>)</div></div><div class='docblock hidden'><p>Extends a collection with exactly one element.</p>
|
||
</div><h4 id="method.extend_reserve" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#method.extend_reserve" class="fnname">extend_reserve</a>(&mut self, additional: usize)</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/iter/traits/collect.rs.html#348" title="goto source code">[src]</a></h4><div class="item-info hidden"><div class="stab unstable"><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>extend_one</code>)</div></div><div class='docblock hidden'><p>Reserves capacity in a collection for the given number of additional elements. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.Extend.html#method.extend_reserve">Read more</a></p>
|
||
</div></div><h3 id="impl-FromIterator%3C(K%2C%20V)%3E" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.FromIterator.html" title="trait core::iter::traits::collect::FromIterator">FromIterator</a><(K, V)> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a>, </span></code><a href="#impl-FromIterator%3C(K%2C%20V)%3E" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#3002-3016" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.from_iter" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.FromIterator.html#tymethod.from_iter" class="fnname">from_iter</a><T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a><Item = (K, V)>>(iter: T) -> Self</code><a class="srclink" href="../src/hashbrown/map.rs.html#3008-3015" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Creates a value from an iterator. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.FromIterator.html#tymethod.from_iter">Read more</a></p>
|
||
</div></div><h3 id="impl-Index%3C%26%27_%20Q%3E" class="impl"><code class="in-band">impl<K, Q: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a><&'_ Q> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,<br> Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>, </span></code><a href="#impl-Index%3C%26%27_%20Q%3E" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#1171-1188" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Output" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/ops/index/trait.Index.html#associatedtype.Output" class="type">Output</a> = V</code></h4><div class='docblock'><p>The returned type after indexing.</p>
|
||
</div><h4 id="method.index" class="method"><code>fn <a href="https://doc.rust-lang.org/nightly/core/ops/index/trait.Index.html#tymethod.index" class="fnname">index</a>(&self, key: &Q) -> &V</code><a class="srclink" href="../src/hashbrown/map.rs.html#1185-1187" title="goto source code">[src]</a></h4><div class="docblock"><p>Returns a reference to the value corresponding to the supplied key.</p>
|
||
<h1 id="panics-1" class="section-header"><a href="#panics-1">Panics</a></h1>
|
||
<p>Panics if the key is not present in the <code>HashMap</code>.</p>
|
||
</div></div><h3 id="impl-IntoIterator" class="impl"><code class="in-band">impl<'a, K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for &'a <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S></code><a href="#impl-IntoIterator" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#2101-2109" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Item" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="type">Item</a> = (&'a K, &'a V)</code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id="associatedtype.IntoIter" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="type">IntoIter</a> = <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'a, K, V></code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id="method.into_iter" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'a, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.Iter.html" title="struct hashbrown::hash_map::Iter">Iter</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (&'a K, &'a V);</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#2106-2108" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></div><h3 id="impl-IntoIterator-1" class="impl"><code class="in-band">impl<'a, K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for &'a mut <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S></code><a href="#impl-IntoIterator-1" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#2111-2119" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Item-1" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="type">Item</a> = (&'a K, &'a mut V)</code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id="associatedtype.IntoIter-1" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="type">IntoIter</a> = <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'a, K, V></code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id="method.into_iter-1" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'a, K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'a, K, V></h3><code class="content"><span class="where fmt-newline">impl<'a, K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.IterMut.html" title="struct hashbrown::hash_map::IterMut">IterMut</a><'a, K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (&'a K, &'a mut V);</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#2116-2118" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
|
||
</div></div><h3 id="impl-IntoIterator-2" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S></code><a href="#impl-IntoIterator-2" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#2121-2148" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Item-2" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="type">Item</a> = (K, V)</code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
|
||
</div><h4 id="associatedtype.IntoIter-2" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="type">IntoIter</a> = <a class="struct" href="../hashbrown/hash_map/struct.IntoIter.html" title="struct hashbrown::hash_map::IntoIter">IntoIter</a><K, V></code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
|
||
</div><h4 id="method.into_iter-2" class="method"><code>fn <a href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fnname">into_iter</a>(self) -> <a class="struct" href="../hashbrown/hash_map/struct.IntoIter.html" title="struct hashbrown::hash_map::IntoIter">IntoIter</a><K, V><span class="notable-traits"><span class="notable-traits-tooltip">ⓘ<div class="notable-traits-tooltiptext"><span class="docblock"><h3 class="notable">Notable traits for <a class="struct" href="../hashbrown/hash_map/struct.IntoIter.html" title="struct hashbrown::hash_map::IntoIter">IntoIter</a><K, V></h3><code class="content"><span class="where fmt-newline">impl<K, V> <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a> for <a class="struct" href="../hashbrown/hash_map/struct.IntoIter.html" title="struct hashbrown::hash_map::IntoIter">IntoIter</a><K, V></span><span class="where fmt-newline"> type <a href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item" class="type">Item</a> = (K, V);</span></code></span></div></span></span></code><a class="srclink" href="../src/hashbrown/map.rs.html#2143-2147" title="goto source code">[src]</a></h4><div class="docblock"><p>Creates a consuming iterator, that is, one that moves each key-value
|
||
pair out of the map in arbitrary order. The map cannot be used after
|
||
calling this.</p>
|
||
<h1 id="examples-29" class="section-header"><a href="#examples-29">Examples</a></h1>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered">
|
||
<span class="kw">use</span> <span class="ident">hashbrown</span>::<span class="ident">HashMap</span>;
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">map</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"a"</span>, <span class="number">1</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"b"</span>, <span class="number">2</span>);
|
||
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">"c"</span>, <span class="number">3</span>);
|
||
|
||
<span class="comment">// Not possible with .iter()</span>
|
||
<span class="kw">let</span> <span class="ident">vec</span>: <span class="ident">Vec</span><span class="op"><</span>(<span class="kw-2">&</span><span class="ident">str</span>, <span class="ident">i32</span>)<span class="op">></span> <span class="op">=</span> <span class="ident">map</span>.<span class="ident">into_iter</span>().<span class="ident">collect</span>();</pre></div>
|
||
</div></div><h3 id="impl-PartialEq%3CHashMap%3CK%2C%20V%2C%20S%3E%3E" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a><<a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S>> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html" title="trait core::cmp::PartialEq">PartialEq</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher">BuildHasher</a>, </span></code><a href="#impl-PartialEq%3CHashMap%3CK%2C%20V%2C%20S%3E%3E" class="anchor"></a><a class="srclink" href="../src/hashbrown/map.rs.html#1126-1140" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.eq" class="method hidden"><code>fn <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq" class="fnname">eq</a>(&self, other: &Self) -> bool</code><a class="srclink" href="../src/hashbrown/map.rs.html#1132-1139" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>self</code> and <code>other</code> values to be equal, and is used
|
||
by <code>==</code>. <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
|
||
</div><h4 id="method.ne" class="method hidden"><code><span class="docblock attributes">#[must_use]</span>pub fn <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialEq.html#method.ne" class="fnname">ne</a>(&self, other: &Rhs) -> bool</code><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/cmp.rs.html#213" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>This method tests for <code>!=</code>.</p>
|
||
</div></div></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><h3 id="impl-Send" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>, </span></code><a href="#impl-Send" class="anchor"></a><a class="srclink" href="../src/hashbrown/lib.rs.html#1" title="goto source code">[src]</a></h3><div class="impl-items"></div><h3 id="impl-Sync" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>, </span></code><a href="#impl-Sync" class="anchor"></a><a class="srclink" href="../src/hashbrown/lib.rs.html#1" title="goto source code">[src]</a></h3><div class="impl-items"></div><h3 id="impl-Unpin" class="impl"><code class="in-band">impl<K, V, S> <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="../hashbrown/hash_map/struct.HashMap.html" title="struct hashbrown::hash_map::HashMap">HashMap</a><K, V, S> <span class="where fmt-newline">where<br> K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> V: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>, </span></code><a href="#impl-Unpin" class="anchor"></a><a class="srclink" href="../src/hashbrown/lib.rs.html#1" title="goto source code">[src]</a></h3><div class="impl-items"></div></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><h3 id="impl-Any" class="impl"><code class="in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T <span class="where fmt-newline">where<br> T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href="#impl-Any" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#131-135" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.type_id" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#132" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></p>
|
||
</div></div><h3 id="impl-Borrow%3CT%3E" class="impl"><code class="in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href="#impl-Borrow%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#207-211" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&self) -> &T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#208" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
|
||
</div></div><h3 id="impl-BorrowMut%3CT%3E" class="impl"><code class="in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T <span class="where fmt-newline">where<br> T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>, </span></code><a href="#impl-BorrowMut%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#214-218" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.borrow_mut" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&mut self) -> &mut T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#215" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
|
||
</div></div><h3 id="impl-From%3CT%3E" class="impl"><code class="in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</code><a href="#impl-From%3CT%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#545-549" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.from" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fnname">from</a>(t: T) -> T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#546" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id="impl-Into%3CU%3E" class="impl"><code class="in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>, </span></code><a href="#impl-Into%3CU%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#534-541" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="method.into" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fnname">into</a>(self) -> U</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#538" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id="impl-ToOwned" class="impl"><code class="in-band">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br> T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span></code><a href="#impl-ToOwned" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#80-92" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Owned" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="type">Owned</a> = T</code></h4><div class='docblock'><p>The resulting type after obtaining ownership.</p>
|
||
</div><h4 id="method.to_owned" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fnname">to_owned</a>(&self) -> T</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#85" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
|
||
</div><h4 id="method.clone_into" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fnname">clone_into</a>(&self, target: &mut T)</code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/alloc/borrow.rs.html#89" title="goto source code">[src]</a></h4><div class="item-info hidden"><div class="stab unstable"><details><summary><span class="emoji">🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>)</summary><p>recently added</p>
|
||
</details></div></div><div class='docblock hidden'><p>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/nightly/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
|
||
</div></div><h3 id="impl-TryFrom%3CU%3E" class="impl"><code class="in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>, </span></code><a href="#impl-TryFrom%3CU%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#582-591" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Error" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="type">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div><h4 id="method.try_from" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#588" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div><h3 id="impl-TryInto%3CU%3E" class="impl"><code class="in-band">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T <span class="where fmt-newline">where<br> U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>, </span></code><a href="#impl-TryInto%3CU%3E" class="anchor"></a><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#568-577" title="goto source code">[src]</a></h3><div class="impl-items"><h4 id="associatedtype.Error-1" class="type"><code>type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="type">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></code></h4><div class='docblock'><p>The type returned in the event of a conversion error.</p>
|
||
</div><h4 id="method.try_into" class="method hidden"><code>pub fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="type" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></code><a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#574" title="goto source code">[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
|
||
</div></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../" data-current-crate="hashbrown"></div>
|
||
<script src="../main.js"></script><script defer src="../search-index.js"></script></body></html> |