Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > 0c2243f8a1696816431e7210e991fa52 > files > 14627

rust-doc-1.35.0-1.mga7.armv7hl.rpm

<!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 `std`."><meta name="keywords" content="rust, rustlang, rust-lang, HashMap"><title>std::collections::HashMap - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize1.35.0.css"><link rel="stylesheet" type="text/css" href="../../rustdoc1.35.0.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark1.35.0.css"><link rel="stylesheet" type="text/css" href="../../light1.35.0.css" id="themeStyle"><script src="../../storage1.35.0.js"></script><noscript><link rel="stylesheet" href="../../noscript1.35.0.css"></noscript><link rel="shortcut icon" href="../../favicon1.35.0.ico"><style type="text/css">#crate-search{background-image:url("../../down-arrow1.35.0.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">&#9776;</div><a href='../../std/index.html'><img src='../../rust-logo1.35.0.png' alt='logo' width='100'></a><p class='location'>Struct HashMap</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">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.entry">entry</a><a href="#method.get">get</a><a href="#method.get_key_value">get_key_value</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.new">new</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">with_capacity</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="#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&lt;(&amp;&#39;a K, &amp;&#39;a V)&gt;</a><a href="#impl-Extend%3C(K%2C%20V)%3E">Extend&lt;(K, V)&gt;</a><a href="#impl-FromIterator%3C(K%2C%20V)%3E">FromIterator&lt;(K, V)&gt;</a><a href="#impl-Index%3C%26%27_%20Q%3E">Index&lt;&amp;&#39;_ Q&gt;</a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-PartialEq%3CHashMap%3CK%2C%20V%2C%20S%3E%3E">PartialEq&lt;HashMap&lt;K, V, S&gt;&gt;</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></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">Borrow</a><a href="#impl-BorrowMut">BorrowMut</a><a href="#impl-From">From</a><a href="#impl-Into">Into</a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-ToOwned">ToOwned</a><a href="#impl-TryFrom">TryFrom</a><a href="#impl-TryInto">TryInto</a></div></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>collections</a></p><script>window.sidebarCurrent = {name: 'HashMap', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush1.35.0.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme1.35.0.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><a id="settings-menu" href="../../settings.html"><img src="../../wheel1.35.0.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/std/collections/hash/map.rs.html#409-416' title='goto source code'>[src]</a></span><span class='in-band'>Struct <a href='../index.html'>std</a>::<wbr><a href='index.html'>collections</a>::<wbr><a class="struct" href=''>HashMap</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct HashMap&lt;K, V, S&nbsp;=&nbsp;<a class="struct" href="../../std/collections/hash_map/struct.RandomState.html" title="struct std::collections::hash_map::RandomState">RandomState</a>&gt; { /* fields omitted */ }</pre></div><div class='docblock'><p>A hash map implemented with linear probing and Robin Hood bucket stealing.</p>
<p>By default, <code>HashMap</code> uses a hashing algorithm selected to provide
resistance against HashDoS attacks. The algorithm is randomly seeded, and a
reasonable best-effort is made to generate this seed from a high quality,
secure source of randomness provided by the host without blocking the
program. Because of this, the randomness of the seed depends on the output
quality of the system's random number generator when the seed is created.
In particular, seeds generated when the system's entropy pool is abnormally
low such as during system boot may be of a lower quality.</p>
<p>The default hashing algorithm is currently SipHash 1-3, though this is
subject to change at any point in the future. While its performance is very
competitive for medium sized keys, other hashing algorithms will outperform
it for small keys such as integers as well as large keys such as long
strings, though those algorithms 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="../../std/cmp/trait.Eq.html"><code>Eq</code></a> and <a href="../../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 -&gt; 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="../../std/hash/trait.Hash.html"><code>Hash</code></a> trait, or its equality, as determined by
the <a href="../../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="../../std/cell/struct.Cell.html"><code>Cell</code></a>, <a href="../../std/cell/struct.RefCell.html"><code>RefCell</code></a>, global state, I/O, or unsafe code.</p>
<p>Relevant papers/articles:</p>
<ol>
<li>Pedro Celis. <a href="https://cs.uwaterloo.ca/research/tr/1986/CS-86-14.pdf">&quot;Robin Hood Hashing&quot;</a></li>
<li>Emmanuel Goossaert. <a href="http://codecapsule.com/2013/11/11/robin-hood-hashing/">&quot;Robin Hood
hashing&quot;</a></li>
<li>Emmanuel Goossaert. <a href="http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/">&quot;Robin Hood hashing: backward shift
deletion&quot;</a></li>
</ol>
<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">std</span>::<span class="ident">collections</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&lt;String, String&gt;` 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">&quot;Adventures of Huckleberry Finn&quot;</span>.<span class="ident">to_string</span>(),
    <span class="string">&quot;My favorite book.&quot;</span>.<span class="ident">to_string</span>(),
);
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
    <span class="string">&quot;Grimms&#39; Fairy Tales&quot;</span>.<span class="ident">to_string</span>(),
    <span class="string">&quot;Masterpiece.&quot;</span>.<span class="ident">to_string</span>(),
);
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
    <span class="string">&quot;Pride and Prejudice&quot;</span>.<span class="ident">to_string</span>(),
    <span class="string">&quot;Very enjoyable.&quot;</span>.<span class="ident">to_string</span>(),
);
<span class="ident">book_reviews</span>.<span class="ident">insert</span>(
    <span class="string">&quot;The Adventures of Sherlock Holmes&quot;</span>.<span class="ident">to_string</span>(),
    <span class="string">&quot;Eye lyked it alot.&quot;</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 (&amp;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">&quot;Les Misérables&quot;</span>) {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;We&#39;ve got {} reviews, but Les Misérables ain&#39;t one.&quot;</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&#39;s delete it.</span>
<span class="ident">book_reviews</span>.<span class="ident">remove</span>(<span class="string">&quot;The Adventures of Sherlock Holmes&quot;</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">&quot;Pride and Prejudice&quot;</span>, <span class="string">&quot;Alice&#39;s Adventure in Wonderland&quot;</span>];
<span class="kw">for</span> <span class="kw-2">&amp;</span><span class="ident">book</span> <span class="kw">in</span> <span class="kw-2">&amp;</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">=&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}: {}&quot;</span>, <span class="ident">book</span>, <span class="ident">review</span>),
        <span class="prelude-val">None</span> <span class="op">=&gt;</span> <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{} is unreviewed.&quot;</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">&quot;Review for Jane: {}&quot;</span>, <span class="ident">book_reviews</span>[<span class="string">&quot;Pride and Prejudice&quot;</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">&amp;</span><span class="ident">book_reviews</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}: \&quot;{}\&quot;&quot;</span>, <span class="ident">book</span>, <span class="ident">review</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0A%2F%2F%20Type%20inference%20lets%20us%20omit%20an%20explicit%20type%20signature%20(which%0A%2F%2F%20would%20be%20%60HashMap%3CString%2C%20String%3E%60%20in%20this%20example).%0Alet%20mut%20book_reviews%20%3D%20HashMap%3A%3Anew()%3B%0A%0A%2F%2F%20Review%20some%20books.%0Abook_reviews.insert(%0A%20%20%20%20%22Adventures%20of%20Huckleberry%20Finn%22.to_string()%2C%0A%20%20%20%20%22My%20favorite%20book.%22.to_string()%2C%0A)%3B%0Abook_reviews.insert(%0A%20%20%20%20%22Grimms'%20Fairy%20Tales%22.to_string()%2C%0A%20%20%20%20%22Masterpiece.%22.to_string()%2C%0A)%3B%0Abook_reviews.insert(%0A%20%20%20%20%22Pride%20and%20Prejudice%22.to_string()%2C%0A%20%20%20%20%22Very%20enjoyable.%22.to_string()%2C%0A)%3B%0Abook_reviews.insert(%0A%20%20%20%20%22The%20Adventures%20of%20Sherlock%20Holmes%22.to_string()%2C%0A%20%20%20%20%22Eye%20lyked%20it%20alot.%22.to_string()%2C%0A)%3B%0A%0A%2F%2F%20Check%20for%20a%20specific%20one.%0A%2F%2F%20When%20collections%20store%20owned%20values%20(String)%2C%20they%20can%20still%20be%0A%2F%2F%20queried%20using%20references%20(%26str).%0Aif%20!book_reviews.contains_key(%22Les%20Mis%C3%A9rables%22)%20%7B%0A%20%20%20%20println!(%22We've%20got%20%7B%7D%20reviews%2C%20but%20Les%20Mis%C3%A9rables%20ain't%20one.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20book_reviews.len())%3B%0A%7D%0A%0A%2F%2F%20oops%2C%20this%20review%20has%20a%20lot%20of%20spelling%20mistakes%2C%20let's%20delete%20it.%0Abook_reviews.remove(%22The%20Adventures%20of%20Sherlock%20Holmes%22)%3B%0A%0A%2F%2F%20Look%20up%20the%20values%20associated%20with%20some%20keys.%0Alet%20to_find%20%3D%20%5B%22Pride%20and%20Prejudice%22%2C%20%22Alice's%20Adventure%20in%20Wonderland%22%5D%3B%0Afor%20%26book%20in%20%26to_find%20%7B%0A%20%20%20%20match%20book_reviews.get(book)%20%7B%0A%20%20%20%20%20%20%20%20Some(review)%20%3D%3E%20println!(%22%7B%7D%3A%20%7B%7D%22%2C%20book%2C%20review)%2C%0A%20%20%20%20%20%20%20%20None%20%3D%3E%20println!(%22%7B%7D%20is%20unreviewed.%22%2C%20book)%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20Look%20up%20the%20value%20for%20a%20key%20(will%20panic%20if%20the%20key%20is%20not%20found).%0Aprintln!(%22Review%20for%20Jane%3A%20%7B%7D%22%2C%20book_reviews%5B%22Pride%20and%20Prejudice%22%5D)%3B%0A%0A%2F%2F%20Iterate%20over%20everything.%0Afor%20(book%2C%20review)%20in%20%26book_reviews%20%7B%0A%20%20%20%20println!(%22%7B%7D%3A%20%5C%22%7B%7D%5C%22%22%2C%20book%2C%20review)%3B%0A%7D%0A%7D">Run</a></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">std</span>::<span class="ident">collections</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&lt;&amp;str, u8&gt;` 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">-&gt;</span> <span class="ident">u8</span> {
    <span class="comment">// could actually return some random value here - let&#39;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&#39;t already exist</span>
<span class="ident">player_stats</span>.<span class="ident">entry</span>(<span class="string">&quot;health&quot;</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&#39;t already exist</span>
<span class="ident">player_stats</span>.<span class="ident">entry</span>(<span class="string">&quot;defence&quot;</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">&quot;attack&quot;</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="ident">random_stat_buff</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0A%2F%2F%20type%20inference%20lets%20us%20omit%20an%20explicit%20type%20signature%20(which%0A%2F%2F%20would%20be%20%60HashMap%3C%26str%2C%20u8%3E%60%20in%20this%20example).%0Alet%20mut%20player_stats%20%3D%20HashMap%3A%3Anew()%3B%0A%0Afn%20random_stat_buff()%20-%3E%20u8%20%7B%0A%20%20%20%20%2F%2F%20could%20actually%20return%20some%20random%20value%20here%20-%20let's%20just%20return%0A%20%20%20%20%2F%2F%20some%20fixed%20value%20for%20now%0A%20%20%20%2042%0A%7D%0A%0A%2F%2F%20insert%20a%20key%20only%20if%20it%20doesn't%20already%20exist%0Aplayer_stats.entry(%22health%22).or_insert(100)%3B%0A%0A%2F%2F%20insert%20a%20key%20using%20a%20function%20that%20provides%20a%20new%20value%20only%20if%20it%0A%2F%2F%20doesn't%20already%20exist%0Aplayer_stats.entry(%22defence%22).or_insert_with(random_stat_buff)%3B%0A%0A%2F%2F%20update%20a%20key%2C%20guarding%20against%20the%20key%20possibly%20not%20being%20set%0Alet%20stat%20%3D%20player_stats.entry(%22attack%22).or_insert(100)%3B%0A*stat%20%2B%3D%20random_stat_buff()%3B%0A%7D">Run</a></pre></div>
<p>The easiest way to use <code>HashMap</code> with a custom key type is to derive <a href="../../std/cmp/trait.Eq.html"><code>Eq</code></a> and <a href="../../std/hash/trait.Hash.html"><code>Hash</code></a>.
We must also derive <a href="../../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">std</span>::<span class="ident">collections</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">&amp;</span><span class="ident">str</span>, <span class="ident">country</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>) <span class="op">-&gt;</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&#39; 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">&quot;Einar&quot;</span>, <span class="string">&quot;Norway&quot;</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">&quot;Olaf&quot;</span>, <span class="string">&quot;Denmark&quot;</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">&quot;Harald&quot;</span>, <span class="string">&quot;Iceland&quot;</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">&amp;</span><span class="ident">vikings</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?} has {} hp&quot;</span>, <span class="ident">viking</span>, <span class="ident">health</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0A%23%5Bderive(Hash%2C%20Eq%2C%20PartialEq%2C%20Debug)%5D%0Astruct%20Viking%20%7B%0A%20%20%20%20name%3A%20String%2C%0A%20%20%20%20country%3A%20String%2C%0A%7D%0A%0Aimpl%20Viking%20%7B%0A%20%20%20%20%2F%2F%2F%20Creates%20a%20new%20Viking.%0A%20%20%20%20fn%20new(name%3A%20%26str%2C%20country%3A%20%26str)%20-%3E%20Viking%20%7B%0A%20%20%20%20%20%20%20%20Viking%20%7B%20name%3A%20name.to_string()%2C%20country%3A%20country.to_string()%20%7D%0A%20%20%20%20%7D%0A%7D%0A%0A%2F%2F%20Use%20a%20HashMap%20to%20store%20the%20vikings'%20health%20points.%0Alet%20mut%20vikings%20%3D%20HashMap%3A%3Anew()%3B%0A%0Avikings.insert(Viking%3A%3Anew(%22Einar%22%2C%20%22Norway%22)%2C%2025)%3B%0Avikings.insert(Viking%3A%3Anew(%22Olaf%22%2C%20%22Denmark%22)%2C%2024)%3B%0Avikings.insert(Viking%3A%3Anew(%22Harald%22%2C%20%22Iceland%22)%2C%2012)%3B%0A%0A%2F%2F%20Use%20derived%20implementation%20to%20print%20the%20status%20of%20the%20vikings.%0Afor%20(viking%2C%20health)%20in%20%26vikings%20%7B%0A%20%20%20%20println!(%22%7B%3A%3F%7D%20has%20%7B%7D%20hp%22%2C%20viking%2C%20health)%3B%0A%7D%0A%7D">Run</a></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">std</span>::<span class="ident">collections</span>::<span class="ident">HashMap</span>;

<span class="kw">fn</span> <span class="ident">main</span>() {
    <span class="kw">let</span> <span class="ident">timber_resources</span>: <span class="ident">HashMap</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span>
    [(<span class="string">&quot;Norway&quot;</span>, <span class="number">100</span>),
     (<span class="string">&quot;Denmark&quot;</span>, <span class="number">50</span>),
     (<span class="string">&quot;Iceland&quot;</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>
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20timber_resources%3A%20HashMap%3C%26str%2C%20i32%3E%20%3D%0A%20%20%20%20%5B(%22Norway%22%2C%20100)%2C%0A%20%20%20%20%20(%22Denmark%22%2C%2050)%2C%0A%20%20%20%20%20(%22Iceland%22%2C%2010)%5D%0A%20%20%20%20%20.iter().cloned().collect()%3B%0A%20%20%20%20%2F%2F%20use%20the%20values%20stored%20in%20map%0A%7D">Run</a></pre></div>
</div><h2 id='methods' class='small-section-header'>Methods<a href='#methods' class='anchor'></a></h2><h3 id='impl' class='impl'><code class='in-band'>impl&lt;K:&nbsp;<a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>, V&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, <a class="struct" href="../../std/collections/hash_map/struct.RandomState.html" title="struct std::collections::hash_map::RandomState">RandomState</a>&gt;</code><a href='#impl' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#683-717' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.new' class="method"><code id='new.v'>pub fn <a href='#method.new' class='fnname'>new</a>() -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, <a class="struct" href="../../std/collections/hash_map/struct.RandomState.html" title="struct std::collections::hash_map::RandomState">RandomState</a>&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#697-699' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashMap</code>.</p>
<p>The hash map is initially created with a capacity of 0, so it will not allocate until it
is first inserted into.</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">std</span>::<span class="ident">collections</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">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">new</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Alet%20mut%20map%3A%20HashMap%3C%26str%2C%20i32%3E%20%3D%20HashMap%3A%3Anew()%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.with_capacity' class="method"><code id='with_capacity.v'>pub fn <a href='#method.with_capacity' class='fnname'>with_capacity</a>(capacity: <a class="primitive" href="../primitive.usize.html">usize</a>) -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, <a class="struct" href="../../std/collections/hash_map/struct.RandomState.html" title="struct std::collections::hash_map::RandomState">RandomState</a>&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#714-716' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashMap</code> with the specified capacity.</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>
<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">std</span>::<span class="ident">collections</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">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashMap</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Alet%20mut%20map%3A%20HashMap%3C%26str%2C%20i32%3E%20%3D%20HashMap%3A%3Awith_capacity(10)%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-1' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a href='#impl-1' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#719-943' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.capacity' class="method"><code id='capacity.v'>pub fn <a href='#method.capacity' class='fnname'>capacity</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.usize.html">usize</a></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#734-736' 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&lt;K, V&gt;</code> might be able to hold
more, but is guaranteed to be able to hold at least this many.</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">std</span>::<span class="ident">collections</span>::<span class="ident">HashMap</span>;
<span class="kw">let</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">&gt;</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">&gt;=</span> <span class="number">100</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Alet%20map%3A%20HashMap%3Ci32%2C%20i32%3E%20%3D%20HashMap%3A%3Awith_capacity(100)%3B%0Aassert!(map.capacity()%20%3E%3D%20100)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.keys' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Keys.html" title="struct std::collections::hash_map::Keys">Keys</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Keys.html" title="struct std::collections::hash_map::Keys">Keys</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.Keys.html" title="struct std::collections::hash_map::Keys">Keys</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.reference.html">&amp;'a </a>K;</span></code></div></div><code id='keys.v'>pub fn <a href='#method.keys' class='fnname'>keys</a>(&amp;self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.Keys.html" title="struct std::collections::hash_map::Keys">Keys</a>&lt;K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#762-764' 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>&amp;'a K</code>.</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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>, <span class="number">1</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>, <span class="number">2</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;c&quot;</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">&quot;{}&quot;</span>, <span class="ident">key</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(%22a%22%2C%201)%3B%0Amap.insert(%22b%22%2C%202)%3B%0Amap.insert(%22c%22%2C%203)%3B%0A%0Afor%20key%20in%20map.keys()%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20key)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.values' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Values.html" title="struct std::collections::hash_map::Values">Values</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Values.html" title="struct std::collections::hash_map::Values">Values</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.Values.html" title="struct std::collections::hash_map::Values">Values</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.reference.html">&amp;'a </a>V;</span></code></div></div><code id='values.v'>pub fn <a href='#method.values' class='fnname'>values</a>(&amp;self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.Values.html" title="struct std::collections::hash_map::Values">Values</a>&lt;K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#784-786' 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>&amp;'a V</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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>, <span class="number">1</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>, <span class="number">2</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;c&quot;</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">&quot;{}&quot;</span>, <span class="ident">val</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(%22a%22%2C%201)%3B%0Amap.insert(%22b%22%2C%202)%3B%0Amap.insert(%22c%22%2C%203)%3B%0A%0Afor%20val%20in%20map.values()%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20val)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.values_mut' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.ValuesMut.html" title="struct std::collections::hash_map::ValuesMut">ValuesMut</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.ValuesMut.html" title="struct std::collections::hash_map::ValuesMut">ValuesMut</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.ValuesMut.html" title="struct std::collections::hash_map::ValuesMut">ValuesMut</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.reference.html">&amp;'a mut </a>V;</span></code></div></div><code id='values_mut.v'>pub fn <a href='#method.values_mut' class='fnname'>values_mut</a>(&amp;mut self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.ValuesMut.html" title="struct std::collections::hash_map::ValuesMut">ValuesMut</a>&lt;K, V&gt;</code><div class='since' title='Stable since Rust version 1.10.0'>1.10.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#811-813' 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>&amp;'a mut 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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>, <span class="number">1</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>, <span class="number">2</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;c&quot;</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">&quot;{}&quot;</span>, <span class="ident">val</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0A%0Amap.insert(%22a%22%2C%201)%3B%0Amap.insert(%22b%22%2C%202)%3B%0Amap.insert(%22c%22%2C%203)%3B%0A%0Afor%20val%20in%20map.values_mut()%20%7B%0A%20%20%20%20*val%20%3D%20*val%20%2B%2010%3B%0A%7D%0A%0Afor%20val%20in%20map.values()%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20val)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.iter' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a </a>V<a class="primitive" href="../primitive.tuple.html">)</a>;</span></code></div></div><code id='iter.v'>pub fn <a href='#method.iter' class='fnname'>iter</a>(&amp;self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#833-835' 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>(&amp;'a K, &amp;'a 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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>, <span class="number">1</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>, <span class="number">2</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;c&quot;</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">&quot;key: {} val: {}&quot;</span>, <span class="ident">key</span>, <span class="ident">val</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(%22a%22%2C%201)%3B%0Amap.insert(%22b%22%2C%202)%3B%0Amap.insert(%22c%22%2C%203)%3B%0A%0Afor%20(key%2C%20val)%20in%20map.iter()%20%7B%0A%20%20%20%20println!(%22key%3A%20%7B%7D%20val%3A%20%7B%7D%22%2C%20key%2C%20val)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.iter_mut' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a mut </a>V<a class="primitive" href="../primitive.tuple.html">)</a>;</span></code></div></div><code id='iter_mut.v'>pub fn <a href='#method.iter_mut' class='fnname'>iter_mut</a>(&amp;mut self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#861-863' 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>(&amp;'a K, &amp;'a mut 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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>, <span class="number">1</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>, <span class="number">2</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;c&quot;</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="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">&amp;</span><span class="ident">map</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;key: {} val: {}&quot;</span>, <span class="ident">key</span>, <span class="ident">val</span>);
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(%22a%22%2C%201)%3B%0Amap.insert(%22b%22%2C%202)%3B%0Amap.insert(%22c%22%2C%203)%3B%0A%0A%2F%2F%20Update%20all%20values%0Afor%20(_%2C%20val)%20in%20map.iter_mut()%20%7B%0A%20%20%20%20*val%20*%3D%202%3B%0A%7D%0A%0Afor%20(key%2C%20val)%20in%20%26map%20%7B%0A%20%20%20%20println!(%22key%3A%20%7B%7D%20val%3A%20%7B%7D%22%2C%20key%2C%20val)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div><h4 id='method.len' class="method"><code id='len.v'>pub fn <a href='#method.len' class='fnname'>len</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.usize.html">usize</a></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#878-880' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the number of elements in the map.</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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20a%20%3D%20HashMap%3A%3Anew()%3B%0Aassert_eq!(a.len()%2C%200)%3B%0Aa.insert(1%2C%20%22a%22)%3B%0Aassert_eq!(a.len()%2C%201)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.is_empty' class="method"><code id='is_empty.v'>pub fn <a href='#method.is_empty' class='fnname'>is_empty</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#896-898' 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-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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20a%20%3D%20HashMap%3A%3Anew()%3B%0Aassert!(a.is_empty())%3B%0Aa.insert(1%2C%20%22a%22)%3B%0Aassert!(!a.is_empty())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.drain' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Drain.html" title="struct std::collections::hash_map::Drain">Drain</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Drain.html" title="struct std::collections::hash_map::Drain">Drain</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.Drain.html" title="struct std::collections::hash_map::Drain">Drain</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>;</span></code></div></div><code id='drain.v'>pub fn <a href='#method.drain' class='fnname'>drain</a>(&amp;mut self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.Drain.html" title="struct std::collections::hash_map::Drain">Drain</a>&lt;K, V&gt;</code><div class='since' title='Stable since Rust version 1.6.0'>1.6.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#921-923' 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-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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>);
<span class="ident">a</span>.<span class="ident">insert</span>(<span class="number">2</span>, <span class="string">&quot;b&quot;</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="number">1</span> <span class="op">||</span> <span class="ident">k</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="string">&quot;a&quot;</span> <span class="op">||</span> <span class="ident">v</span> <span class="op">==</span> <span class="string">&quot;b&quot;</span>);
}

<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_empty</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20a%20%3D%20HashMap%3A%3Anew()%3B%0Aa.insert(1%2C%20%22a%22)%3B%0Aa.insert(2%2C%20%22b%22)%3B%0A%0Afor%20(k%2C%20v)%20in%20a.drain().take(1)%20%7B%0A%20%20%20%20assert!(k%20%3D%3D%201%20%7C%7C%20k%20%3D%3D%202)%3B%0A%20%20%20%20assert!(v%20%3D%3D%20%22a%22%20%7C%7C%20v%20%3D%3D%20%22b%22)%3B%0A%7D%0A%0Aassert!(a.is_empty())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.clear' class="method"><code id='clear.v'>pub fn <a href='#method.clear' class='fnname'>clear</a>(&amp;mut self)</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#940-942' 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-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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20a%20%3D%20HashMap%3A%3Anew()%3B%0Aa.insert(1%2C%20%22a%22)%3B%0Aa.clear()%3B%0Aassert!(a.is_empty())%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-2' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-2' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#945-1535' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.with_hasher' class="method"><code id='with_hasher.v'>pub fn <a href='#method.with_hasher' class='fnname'>with_hasher</a>(hash_builder: S) -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#971-977' 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>
<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">std</span>::<span class="ident">collections</span>::<span class="ident">HashMap</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">hash_map</span>::<span class="ident">RandomState</span>;

<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">RandomState</span>::<span class="ident">new</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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Ause%20std%3A%3Acollections%3A%3Ahash_map%3A%3ARandomState%3B%0A%0Alet%20s%20%3D%20RandomState%3A%3Anew()%3B%0Alet%20mut%20map%20%3D%20HashMap%3A%3Awith_hasher(s)%3B%0Amap.insert(1%2C%202)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.with_capacity_and_hasher' class="method"><code id='with_capacity_and_hasher.v'>pub fn <a href='#method.with_capacity_and_hasher' class='fnname'>with_capacity_and_hasher</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;capacity: <a class="primitive" href="../primitive.usize.html">usize</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;hash_builder: S<br>) -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><div class='since' title='Stable since Rust version 1.7.0'>1.7.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1002-1010' 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>
<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">std</span>::<span class="ident">collections</span>::<span class="ident">HashMap</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">hash_map</span>::<span class="ident">RandomState</span>;

<span class="kw">let</span> <span class="ident">s</span> <span class="op">=</span> <span class="ident">RandomState</span>::<span class="ident">new</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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Ause%20std%3A%3Acollections%3A%3Ahash_map%3A%3ARandomState%3B%0A%0Alet%20s%20%3D%20RandomState%3A%3Anew()%3B%0Alet%20mut%20map%20%3D%20HashMap%3A%3Awith_capacity_and_hasher(10%2C%20s)%3B%0Amap.insert(1%2C%202)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.hasher' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</h3><code class="content"><span class="where fmt-newline">impl&lt;'_, F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;'_, I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>R</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>W</span></code></div></div><code id='hasher.v'>pub fn <a href='#method.hasher' class='fnname'>hasher</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.reference.html">&amp;</a>S</code><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1027-1029' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a reference to the map's <a href="../../std/hash/trait.BuildHasher.html"><code>BuildHasher</code></a>.</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">std</span>::<span class="ident">collections</span>::<span class="ident">HashMap</span>;
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">hash_map</span>::<span class="ident">RandomState</span>;

<span class="kw">let</span> <span class="ident">hasher</span> <span class="op">=</span> <span class="ident">RandomState</span>::<span class="ident">new</span>();
<span class="kw">let</span> <span class="ident">map</span>: <span class="ident">HashMap</span><span class="op">&lt;</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">&gt;</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">&amp;</span><span class="ident">RandomState</span> <span class="op">=</span> <span class="ident">map</span>.<span class="ident">hasher</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Ause%20std%3A%3Acollections%3A%3Ahash_map%3A%3ARandomState%3B%0A%0Alet%20hasher%20%3D%20RandomState%3A%3Anew()%3B%0Alet%20map%3A%20HashMap%3Ci32%2C%20i32%3E%20%3D%20HashMap%3A%3Awith_hasher(hasher)%3B%0Alet%20hasher%3A%20%26RandomState%20%3D%20map.hasher()%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.reserve' class="method"><code id='reserve.v'>pub fn <a href='#method.reserve' class='fnname'>reserve</a>(&amp;mut self, additional: <a class="primitive" href="../primitive.usize.html">usize</a>)</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1050-1056' 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="../../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">std</span>::<span class="ident">collections</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">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">i32</span><span class="op">&gt;</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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Alet%20mut%20map%3A%20HashMap%3C%26str%2C%20i32%3E%20%3D%20HashMap%3A%3Anew()%3B%0Amap.reserve(10)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.try_reserve' class="method"><code id='try_reserve.v'>pub fn <a href='#method.try_reserve' class='fnname'>try_reserve</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;additional: <a class="primitive" href="../primitive.usize.html">usize</a><br>) -&gt; <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;<a class="primitive" href="../primitive.unit.html">()</a>, <a class="enum" href="../../std/collections/enum.CollectionAllocErr.html" title="enum std::collections::CollectionAllocErr">CollectionAllocErr</a>&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1076-1078' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>try_reserve</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/48043">#48043</a>)</summary><p>new API</p>
</details></div></div><div class='docblock'><p>Tries to reserve capacity for at least <code>additional</code> more elements to be inserted
in the given <code>HashMap&lt;K,V&gt;</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="attribute">#![<span class="ident">feature</span>(<span class="ident">try_reserve</span>)]</span>
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</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">&lt;</span><span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">isize</span><span class="op">&gt;</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">&quot;why is the test harness OOMing on 10 bytes?&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Bfeature(try_reserve)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0Alet%20mut%20map%3A%20HashMap%3C%26str%2C%20isize%3E%20%3D%20HashMap%3A%3Anew()%3B%0Amap.try_reserve(10).expect(%22why%20is%20the%20test%20harness%20OOMing%20on%2010%20bytes%3F%22)%3B%0A%7D&amp;version=nightly">Run</a></pre></div>
</div><h4 id='method.shrink_to_fit' class="method"><code id='shrink_to_fit.v'>pub fn <a href='#method.shrink_to_fit' class='fnname'>shrink_to_fit</a>(&amp;mut self)</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1180-1193' 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">std</span>::<span class="ident">collections</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">&lt;</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">&gt;</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">&gt;=</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">&gt;=</span> <span class="number">2</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%3A%20HashMap%3Ci32%2C%20i32%3E%20%3D%20HashMap%3A%3Awith_capacity(100)%3B%0Amap.insert(1%2C%202)%3B%0Amap.insert(3%2C%204)%3B%0Aassert!(map.capacity()%20%3E%3D%20100)%3B%0Amap.shrink_to_fit()%3B%0Aassert!(map.capacity()%20%3E%3D%202)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.shrink_to' class="method"><code id='shrink_to.v'>pub fn <a href='#method.shrink_to' class='fnname'>shrink_to</a>(&amp;mut self, min_capacity: <a class="primitive" href="../primitive.usize.html">usize</a>)</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1218-1233' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>shrink_to</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/56431">#56431</a>)</summary><p>new API</p>
</details></div></div><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>Panics 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="attribute">#![<span class="ident">feature</span>(<span class="ident">shrink_to</span>)]</span>
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</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">&lt;</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">&gt;</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">&gt;=</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">&gt;=</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">&gt;=</span> <span class="number">2</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Bfeature(shrink_to)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%3A%20HashMap%3Ci32%2C%20i32%3E%20%3D%20HashMap%3A%3Awith_capacity(100)%3B%0Amap.insert(1%2C%202)%3B%0Amap.insert(3%2C%204)%3B%0Aassert!(map.capacity()%20%3E%3D%20100)%3B%0Amap.shrink_to(10)%3B%0Aassert!(map.capacity()%20%3E%3D%2010)%3B%0Amap.shrink_to(0)%3B%0Aassert!(map.capacity()%20%3E%3D%202)%3B%0A%7D&amp;version=nightly">Run</a></pre></div>
</div><h4 id='method.entry' class="method"><code id='entry.v'>pub fn <a href='#method.entry' class='fnname'>entry</a>(&amp;mut self, key: K) -&gt; <a class="enum" href="../../std/collections/hash_map/enum.Entry.html" title="enum std::collections::hash_map::Entry">Entry</a>&lt;K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1273-1279' 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">std</span>::<span class="ident">collections</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">&quot;a short treatise on fungi&quot;</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="number">1</span>;
}

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">letters</span>[<span class="kw-2">&amp;</span><span class="string">&#39;s&#39;</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">&amp;</span><span class="string">&#39;t&#39;</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">&amp;</span><span class="string">&#39;u&#39;</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">&amp;</span><span class="string">&#39;y&#39;</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20letters%20%3D%20HashMap%3A%3Anew()%3B%0A%0Afor%20ch%20in%20%22a%20short%20treatise%20on%20fungi%22.chars()%20%7B%0A%20%20%20%20let%20counter%20%3D%20letters.entry(ch).or_insert(0)%3B%0A%20%20%20%20*counter%20%2B%3D%201%3B%0A%7D%0A%0Aassert_eq!(letters%5B%26's'%5D%2C%202)%3B%0Aassert_eq!(letters%5B%26't'%5D%2C%203)%3B%0Aassert_eq!(letters%5B%26'u'%5D%2C%201)%3B%0Aassert_eq!(letters.get(%26'y')%2C%20None)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.get' class="method"><code id='get.v'>pub fn <a href='#method.get' class='fnname'>get</a>&lt;Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;self, k: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="primitive" href="../primitive.reference.html">&amp;</a>V&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,&nbsp;</span></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1302-1307' 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="../../std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="../../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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&amp;</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="string">&quot;a&quot;</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">&amp;</span><span class="number">2</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(1%2C%20%22a%22)%3B%0Aassert_eq!(map.get(%261)%2C%20Some(%26%22a%22))%3B%0Aassert_eq!(map.get(%262)%2C%20None)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.get_key_value' class="method"><code id='get_key_value.v'>pub fn <a href='#method.get_key_value' class='fnname'>get_key_value</a>&lt;Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;self, k: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;</a>K, <a class="primitive" href="../primitive.reference.html">&amp;</a>V<a class="primitive" href="../primitive.tuple.html">)</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,&nbsp;</span></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1330-1335' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>map_get_key_value</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/49347">#49347</a>)</div></div><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="../../std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="../../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="attribute">#![<span class="ident">feature</span>(<span class="ident">map_get_key_value</span>)]</span>
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&amp;</span><span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="kw-2">&amp;</span><span class="number">1</span>, <span class="kw-2">&amp;</span><span class="string">&quot;a&quot;</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">&amp;</span><span class="number">2</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0A%23!%5Bfeature(map_get_key_value)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(1%2C%20%22a%22)%3B%0Aassert_eq!(map.get_key_value(%261)%2C%20Some((%261%2C%20%26%22a%22)))%3B%0Aassert_eq!(map.get_key_value(%262)%2C%20None)%3B%0A%7D&amp;version=nightly">Run</a></pre></div>
</div><h4 id='method.contains_key' class="method"><code id='contains_key.v'>pub fn <a href='#method.contains_key' class='fnname'>contains_key</a>&lt;Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;self, k: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,&nbsp;</span></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1357-1362' 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="../../std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="../../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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&amp;</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">&amp;</span><span class="number">2</span>), <span class="bool-val">false</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(1%2C%20%22a%22)%3B%0Aassert_eq!(map.contains_key(%261)%2C%20true)%3B%0Aassert_eq!(map.contains_key(%262)%2C%20false)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.get_mut' class="method"><code id='get_mut.v'>pub fn <a href='#method.get_mut' class='fnname'>get_mut</a>&lt;Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;mut self, k: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="primitive" href="../primitive.reference.html">&amp;mut </a>V&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,&nbsp;</span></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1386-1391' 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="../../std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="../../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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&amp;</span><span class="number">1</span>) {
    <span class="kw-2">*</span><span class="ident">x</span> <span class="op">=</span> <span class="string">&quot;b&quot;</span>;
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>[<span class="kw-2">&amp;</span><span class="number">1</span>], <span class="string">&quot;b&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(1%2C%20%22a%22)%3B%0Aif%20let%20Some(x)%20%3D%20map.get_mut(%261)%20%7B%0A%20%20%20%20*x%20%3D%20%22b%22%3B%0A%7D%0Aassert_eq!(map%5B%261%5D%2C%20%22b%22)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.insert' class="method"><code id='insert.v'>pub fn <a href='#method.insert' class='fnname'>insert</a>(&amp;mut self, k: K, v: V) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1419-1423' 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="../../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-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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&quot;b&quot;</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">&quot;c&quot;</span>), <span class="prelude-val">Some</span>(<span class="string">&quot;b&quot;</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">map</span>[<span class="kw-2">&amp;</span><span class="number">37</span>], <span class="string">&quot;c&quot;</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Aassert_eq!(map.insert(37%2C%20%22a%22)%2C%20None)%3B%0Aassert_eq!(map.is_empty()%2C%20false)%3B%0A%0Amap.insert(37%2C%20%22b%22)%3B%0Aassert_eq!(map.insert(37%2C%20%22c%22)%2C%20Some(%22b%22))%3B%0Aassert_eq!(map%5B%2637%5D%2C%20%22c%22)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.remove' class="method"><code id='remove.v'>pub fn <a href='#method.remove' class='fnname'>remove</a>&lt;Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;mut self, k: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;V&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,&nbsp;</span></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1446-1451' 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="../../std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="../../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-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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&amp;</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="string">&quot;a&quot;</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">&amp;</span><span class="number">1</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(1%2C%20%22a%22)%3B%0Aassert_eq!(map.remove(%261)%2C%20Some(%22a%22))%3B%0Aassert_eq!(map.remove(%261)%2C%20None)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.remove_entry' class="method"><code id='remove_entry.v'>pub fn <a href='#method.remove_entry' class='fnname'>remove_entry</a>&lt;Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;mut self, k: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.27.0'>1.27.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1476-1485' 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="../../std/hash/trait.Hash.html"><code>Hash</code></a> and <a href="../../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">std</span>::<span class="ident">collections</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">&quot;a&quot;</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">&amp;</span><span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">&quot;a&quot;</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">&amp;</span><span class="number">1</span>), <span class="prelude-val">None</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Afn%20main()%20%7B%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(1%2C%20%22a%22)%3B%0Aassert_eq!(map.remove_entry(%261)%2C%20Some((1%2C%20%22a%22)))%3B%0Aassert_eq!(map.remove(%261)%2C%20None)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.retain' class="method"><code id='retain.v'>pub fn <a href='#method.retain' class='fnname'>retain</a>&lt;F&gt;(&amp;mut self, f: F) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/ops/trait.FnMut.html" title="trait std::ops::FnMut">FnMut</a>(<a class="primitive" href="../primitive.reference.html">&amp;</a>K, <a class="primitive" href="../primitive.reference.html">&amp;mut </a>V) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a>,&nbsp;</span></code><div class='since' title='Stable since Rust version 1.18.0'>1.18.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1501-1534' 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(&amp;k,&amp;mut v)</code> returns <code>false</code>.</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">std</span>::<span class="ident">collections</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">&lt;</span><span class="ident">i32</span>, <span class="ident">i32</span><span class="op">&gt;</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">&amp;</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="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>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%3A%20HashMap%3Ci32%2C%20i32%3E%20%3D%20(0..8).map(%7Cx%7C(x%2C%20x*10)).collect()%3B%0Amap.retain(%7C%26k%2C%20_%7C%20k%20%25%202%20%3D%3D%200)%3B%0Aassert_eq!(map.len()%2C%204)%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-3' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-3' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1537-1598' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.raw_entry_mut' class="method"><code id='raw_entry_mut.v'>pub fn <a href='#method.raw_entry_mut' class='fnname'>raw_entry_mut</a>(&amp;mut self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.RawEntryBuilderMut.html" title="struct std::collections::hash_map::RawEntryBuilderMut">RawEntryBuilderMut</a>&lt;K, V, S&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1574-1577' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>hash_raw_entry</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/56167">#56167</a>)</div></div><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 &quot;lost&quot; 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 id='raw_entry.v'>pub fn <a href='#method.raw_entry' class='fnname'>raw_entry</a>(&amp;self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.RawEntryBuilder.html" title="struct std::collections::hash_map::RawEntryBuilder">RawEntryBuilder</a>&lt;K, V, S&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1595-1597' title='goto source code'>[src]</a></h4><div class='stability'><div class='stab unstable'><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>hash_raw_entry</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/56167">#56167</a>)</div></div><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='implementations' class='small-section-header'>Trait Implementations<a href='#implementations' class='anchor'></a></h2><div id='implementations-list'><h3 id='impl-Debug' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-Debug' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1624-1632' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.fmt' class="method hidden"><code id='fmt.v'>fn <a href='../../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -&gt; <a class="type" href="../../std/fmt/type.Result.html" title="type std::fmt::Result">Result</a></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1629-1631' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Formats the value using the given formatter. <a href="../../std/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-PartialEq%3CHashMap%3CK%2C%20V%2C%20S%3E%3E' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>&lt;<a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;&gt; for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-PartialEq%3CHashMap%3CK%2C%20V%2C%20S%3E%3E' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1601-1613' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.eq' class="method hidden"><code id='eq.v'>fn <a href='../../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&amp;self, other: &amp;<a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1606-1612' 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="../../std/cmp/trait.PartialEq.html#tymethod.eq">Read more</a></p>
</div><h4 id='method.ne' class="method"><code id='ne.v'><div class="docblock attributes">#[must_use]
</div>fn <a href='../../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&amp;self, other: <a class="primitive" href="../primitive.reference.html">&amp;</a>Rhs) -&gt; <a class="primitive" href="../primitive.bool.html">bool</a></code><a class='srclink' href='../../src/core/cmp.rs.html#200' title='goto source code'>[src]</a></h4><div class='docblock'><p>This method tests for <code>!=</code>.</p>
</div></div><h3 id='impl-Eq' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-Eq' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1616-1621' title='goto source code'>[src]</a></h3><div class='impl-items'></div><h3 id='impl-Index%3C%26%27_%20Q%3E' class='impl'><code class='in-band'>impl&lt;K, Q:&nbsp;?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, V, S, '_&gt; <a class="trait" href="../../std/ops/trait.Index.html" title="trait std::ops::Index">Index</a>&lt;<a class="primitive" href="../primitive.reference.html">&amp;'_ </a>Q&gt; for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a>&lt;Q&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;Q: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-Index%3C%26%27_%20Q%3E' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1646-1662' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Output' class="type"><code id='Output.t'>type <a href='../../std/ops/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"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</h3><code class="content"><span class="where fmt-newline">impl&lt;'_, F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;'_, I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>R</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>W</span></code></div></div><code id='index.v'>fn <a href='../../std/ops/trait.Index.html#tymethod.index' class='fnname'>index</a>(&amp;self, key: <a class="primitive" href="../primitive.reference.html">&amp;</a>Q) -&gt; <a class="primitive" href="../primitive.reference.html">&amp;</a>V</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1659-1661' 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-FromIterator%3C(K%2C%20V)%3E' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/iter/trait.FromIterator.html" title="trait std::iter::FromIterator">FromIterator</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>&gt; for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a> + <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a>,&nbsp;</span></code><a href='#impl-FromIterator%3C(K%2C%20V)%3E' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#3083-3092' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from_iter' class="method hidden"><code id='from_iter.v'>fn <a href='../../std/iter/trait.FromIterator.html#tymethod.from_iter' class='fnname'>from_iter</a>&lt;T:&nbsp;<a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>&gt;&gt;(iter: T) -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#3087-3091' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates a value from an iterator. <a href="../../std/iter/trait.FromIterator.html#tymethod.from_iter">Read more</a></p>
</div></div><h3 id='impl-IntoIterator' class='impl'><code class='in-band'>impl&lt;'a, K, V, S&gt; <a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a> for &amp;'a <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a href='#impl-IntoIterator' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#2394-2401' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item' class="type"><code id='Item.t'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a </a>V<a class="primitive" href="../primitive.tuple.html">)</a></code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
</div><h4 id='associatedtype.IntoIter' class="type"><code id='IntoIter.t'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</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"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a </a>V<a class="primitive" href="../primitive.tuple.html">)</a>;</span></code></div></div><code id='into_iter.v'>fn <a href='../../std/iter/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.Iter.html" title="struct std::collections::hash_map::Iter">Iter</a>&lt;'a, K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#2398-2400' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="../../std/iter/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
</div></div><h3 id='impl-IntoIterator-1' class='impl'><code class='in-band'>impl&lt;'a, K, V, S&gt; <a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a> for &amp;'a mut <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a href='#impl-IntoIterator-1' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#2404-2411' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-1' class="type"><code id='Item.t-1'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a mut </a>V<a class="primitive" href="../primitive.tuple.html">)</a></code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
</div><h4 id='associatedtype.IntoIter-1' class="type"><code id='IntoIter.t-1'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</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"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a mut </a>V<a class="primitive" href="../primitive.tuple.html">)</a>;</span></code></div></div><code id='into_iter.v-1'>fn <a href='../../std/iter/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.IterMut.html" title="struct std::collections::hash_map::IterMut">IterMut</a>&lt;'a, K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#2408-2410' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="../../std/iter/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
</div></div><h3 id='impl-IntoIterator-2' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a href='#impl-IntoIterator-2' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#2414-2438' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-2' class="type"><code id='Item.t-2'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a></code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
</div><h4 id='associatedtype.IntoIter-2' class="type"><code id='IntoIter.t-2'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = <a class="struct" href="../../std/collections/hash_map/struct.IntoIter.html" title="struct std::collections::hash_map::IntoIter">IntoIter</a>&lt;K, V&gt;</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"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../std/collections/hash_map/struct.IntoIter.html" title="struct std::collections::hash_map::IntoIter">IntoIter</a>&lt;K, V&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../std/collections/hash_map/struct.IntoIter.html" title="struct std::collections::hash_map::IntoIter">IntoIter</a>&lt;K, V&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;K, V&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="struct" href="../../std/collections/hash_map/struct.IntoIter.html" title="struct std::collections::hash_map::IntoIter">IntoIter</a>&lt;K, V&gt;</span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = <a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>;</span></code></div></div><code id='into_iter.v-2'>fn <a href='../../std/iter/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -&gt; <a class="struct" href="../../std/collections/hash_map/struct.IntoIter.html" title="struct std::collections::hash_map::IntoIter">IntoIter</a>&lt;K, V&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#2435-2437' 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">std</span>::<span class="ident">collections</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">&quot;a&quot;</span>, <span class="number">1</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>, <span class="number">2</span>);
<span class="ident">map</span>.<span class="ident">insert</span>(<span class="string">&quot;c&quot;</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">&lt;</span>(<span class="kw-2">&amp;</span><span class="ident">str</span>, <span class="ident">i32</span>)<span class="op">&gt;</span> <span class="op">=</span> <span class="ident">map</span>.<span class="ident">into_iter</span>().<span class="ident">collect</span>();<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Afn%20main()%20%7B%0Ause%20std%3A%3Acollections%3A%3AHashMap%3B%0A%0Alet%20mut%20map%20%3D%20HashMap%3A%3Anew()%3B%0Amap.insert(%22a%22%2C%201)%3B%0Amap.insert(%22b%22%2C%202)%3B%0Amap.insert(%22c%22%2C%203)%3B%0A%0A%2F%2F%20Not%20possible%20with%20.iter()%0Alet%20vec%3A%20Vec%3C(%26str%2C%20i32)%3E%20%3D%20map.into_iter().collect()%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-Extend%3C(K%2C%20V)%3E' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/iter/trait.Extend.html" title="trait std::iter::Extend">Extend</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>&gt; for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-Extend%3C(K%2C%20V)%3E' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#3095-3115' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.extend' class="method hidden"><code id='extend.v'>fn <a href='../../std/iter/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;T:&nbsp;<a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="../primitive.tuple.html">(</a>K, V<a class="primitive" href="../primitive.tuple.html">)</a>&gt;&gt;(&amp;mut self, iter: T)</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#3099-3114' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Extends a collection with the contents of an iterator. <a href="../../std/iter/trait.Extend.html#tymethod.extend">Read more</a></p>
</div></div><h3 id='impl-Extend%3C(%26%27a%20K%2C%20%26%27a%20V)%3E' class='impl'><code class='in-band'>impl&lt;'a, K, V, S&gt; <a class="trait" href="../../std/iter/trait.Extend.html" title="trait std::iter::Extend">Extend</a>&lt;<a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a </a>V<a class="primitive" href="../primitive.tuple.html">)</a>&gt; for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + <a class="trait" href="../../std/marker/trait.Copy.html" title="trait std::marker::Copy">Copy</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../std/marker/trait.Copy.html" title="trait std::marker::Copy">Copy</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a>,&nbsp;</span></code><a href='#impl-Extend%3C(%26%27a%20K%2C%20%26%27a%20V)%3E' class='anchor'></a><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div><a class='srclink' href='../../src/std/collections/hash/map.rs.html#3118-3126' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.extend-1' class="method hidden"><code id='extend.v-1'>fn <a href='../../std/iter/trait.Extend.html#tymethod.extend' class='fnname'>extend</a>&lt;T:&nbsp;<a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="../primitive.tuple.html">(</a><a class="primitive" href="../primitive.reference.html">&amp;'a </a>K, <a class="primitive" href="../primitive.reference.html">&amp;'a </a>V<a class="primitive" href="../primitive.tuple.html">)</a>&gt;&gt;(&amp;mut self, iter: T)</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#3123-3125' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Extends a collection with the contents of an iterator. <a href="../../std/iter/trait.Extend.html#tymethod.extend">Read more</a></p>
</div></div><h3 id='impl-Clone' class='impl'><code class='in-band'>impl&lt;K:&nbsp;<a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>, V:&nbsp;<a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>, S:&nbsp;<a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>&gt; <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a href='#impl-Clone' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#407' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.clone' class="method hidden"><code id='clone.v'>fn <a href='../../std/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&amp;self) -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#407' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Returns a copy of the value. <a href="../../std/clone/trait.Clone.html#tymethod.clone">Read more</a></p>
</div><h4 id='method.clone_from' class="method"><code id='clone_from.v'>fn <a href='../../std/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&amp;mut self, source: <a class="primitive" href="../primitive.reference.html">&amp;</a>Self)</code><a class='srclink' href='../../src/core/clone.rs.html#131-133' title='goto source code'>[src]</a></h4><div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../../std/clone/trait.Clone.html#method.clone_from">Read more</a></p>
</div></div><h3 id='impl-Default' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/hash/trait.BuildHasher.html" title="trait std::hash::BuildHasher">BuildHasher</a> + <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a>,&nbsp;</span></code><a href='#impl-Default' class='anchor'></a><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1635-1643' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.default' class="method"><code id='default.v'>fn <a href='../../std/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -&gt; <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt;</code><a class='srclink' href='../../src/std/collections/hash/map.rs.html#1640-1642' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashMap&lt;K, V, S&gt;</code>, with the <code>Default</code> value for the hasher.</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&lt;K, V, S&gt; <a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a>,&nbsp;</span></code><a href='#impl-Send' class='anchor'></a></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><code class='in-band'>impl&lt;K, V, S&gt; <a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a> for <a class="struct" href="../../std/collections/struct.HashMap.html" title="struct std::collections::HashMap">HashMap</a>&lt;K, V, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;K: <a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;S: <a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;V: <a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a>,&nbsp;</span></code><a href='#impl-Sync' class='anchor'></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-TryFrom' class='impl'><code class='in-band'>impl&lt;T, U&gt; <a class="trait" href="../../std/convert/trait.TryFrom.html" title="trait std::convert::TryFrom">TryFrom</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="../../std/convert/trait.Into.html" title="trait std::convert::Into">Into</a>&lt;T&gt;,&nbsp;</span></code><a href='#impl-TryFrom' class='anchor'></a><a class='srclink' href='../../src/core/convert.rs.html#565-571' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error' class="type"><code id='Error.t'>type <a href='../../std/convert/trait.TryFrom.html#associatedtype.Error' class="type">Error</a> = <a class="enum" href="../../std/convert/enum.Infallible.html" title="enum std::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 id='try_from.v'>fn <a href='../../std/convert/trait.TryFrom.html#tymethod.try_from' class='fnname'>try_from</a>(value: U) -&gt; <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="../../std/convert/trait.TryFrom.html" title="trait std::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="type" href="../../std/convert/trait.TryFrom.html#associatedtype.Error" title="type std::convert::TryFrom::Error">Error</a>&gt;</code><a class='srclink' href='../../src/core/convert.rs.html#568-570' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a> for T</code><a href='#impl-From' class='anchor'></a><a class='srclink' href='../../src/core/convert.rs.html#546-548' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.from' class="method hidden"><code id='from.v'>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(t: T) -&gt; T</code><a class='srclink' href='../../src/core/convert.rs.html#547' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-IntoIterator-3' class='impl'><code class='in-band'>impl&lt;I&gt; <a class="trait" href="../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a> for I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>,&nbsp;</span></code><a href='#impl-IntoIterator-3' class='anchor'></a><a class='srclink' href='../../src/core/iter/traits/collect.rs.html#241-248' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Item-3' class="type"><code id='Item.t-3'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a></code></h4><div class='docblock'><p>The type of the elements being iterated over.</p>
</div><h4 id='associatedtype.IntoIter-3' class="type"><code id='IntoIter.t-3'>type <a href='../../std/iter/trait.IntoIterator.html#associatedtype.IntoIter' class="type">IntoIter</a> = I</code></h4><div class='docblock'><p>Which kind of iterator are we turning this into?</p>
</div><h4 id='method.into_iter-3' class="method hidden"><code id='into_iter.v-3'>fn <a href='../../std/iter/trait.IntoIterator.html#tymethod.into_iter' class='fnname'>into_iter</a>(self) -&gt; I</code><a class='srclink' href='../../src/core/iter/traits/collect.rs.html#245-247' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates an iterator from a value. <a href="../../std/iter/trait.IntoIterator.html#tymethod.into_iter">Read more</a></p>
</div></div><h3 id='impl-TryInto' class='impl'><code class='in-band'>impl&lt;T, U&gt; <a class="trait" href="../../std/convert/trait.TryInto.html" title="trait std::convert::TryInto">TryInto</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="../../std/convert/trait.TryFrom.html" title="trait std::convert::TryFrom">TryFrom</a>&lt;T&gt;,&nbsp;</span></code><a href='#impl-TryInto' class='anchor'></a><a class='srclink' href='../../src/core/convert.rs.html#553-560' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Error-1' class="type"><code id='Error.t-1'>type <a href='../../std/convert/trait.TryInto.html#associatedtype.Error' class="type">Error</a> = &lt;U as <a class="trait" href="../../std/convert/trait.TryFrom.html" title="trait std::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="type" href="../../std/convert/trait.TryFrom.html#associatedtype.Error" title="type std::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 id='try_into.v'>fn <a href='../../std/convert/trait.TryInto.html#tymethod.try_into' class='fnname'>try_into</a>(self) -&gt; <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="../../std/convert/trait.TryFrom.html" title="trait std::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="type" href="../../std/convert/trait.TryFrom.html#associatedtype.Error" title="type std::convert::TryFrom::Error">Error</a>&gt;</code><a class='srclink' href='../../src/core/convert.rs.html#557-559' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-Into' class='impl'><code class='in-band'>impl&lt;T, U&gt; <a class="trait" href="../../std/convert/trait.Into.html" title="trait std::convert::Into">Into</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a>&lt;T&gt;,&nbsp;</span></code><a href='#impl-Into' class='anchor'></a><a class='srclink' href='../../src/core/convert.rs.html#537-542' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.into' class="method hidden"><code id='into.v'>fn <a href='../../std/convert/trait.Into.html#tymethod.into' class='fnname'>into</a>(self) -&gt; U</code><a class='srclink' href='../../src/core/convert.rs.html#539-541' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Performs the conversion.</p>
</div></div><h3 id='impl-Borrow' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Borrow' class='anchor'></a><a class='srclink' href='../../src/core/borrow.rs.html#213-215' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow' class="method hidden"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</h3><code class="content"><span class="where fmt-newline">impl&lt;'_, F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;'_, I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>R</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>W</span></code></div></div><code id='borrow.v'>fn <a href='../../std/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&amp;self) -&gt; <a class="primitive" href="../primitive.reference.html">&amp;</a>T</code><a class='srclink' href='../../src/core/borrow.rs.html#214' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Immutably borrows from an owned value. <a href="../../std/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p>
</div></div><h3 id='impl-BorrowMut' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/borrow/trait.BorrowMut.html" title="trait std::borrow::BorrowMut">BorrowMut</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-BorrowMut' class='anchor'></a><a class='srclink' href='../../src/core/borrow.rs.html#218-220' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.borrow_mut' class="method hidden"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F</h3><code class="content"><span class="where fmt-newline">impl&lt;'_, F&gt; <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>F <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;F: <a class="trait" href="../../std/marker/trait.Unpin.html" title="trait std::marker::Unpin">Unpin</a> + <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/future/trait.Future.html#associatedtype.Output' class="type">Output</a> = &lt;F as <a class="trait" href="../../std/future/trait.Future.html" title="trait std::future::Future">Future</a>&gt;::<a class="type" href="../../std/future/trait.Future.html#associatedtype.Output" title="type std::future::Future::Output">Output</a>;</span><span class="where fmt-newline">impl&lt;'_, I&gt; <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>I <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;I: <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></span><span class="where fmt-newline">    type <a href='../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &lt;I as <a class="trait" href="../../std/iter/trait.Iterator.html" title="trait std::iter::Iterator">Iterator</a>&gt;::<a class="type" href="../../std/iter/trait.Iterator.html#associatedtype.Item" title="type std::iter::Iterator::Item">Item</a>;</span><span class="where fmt-newline">impl&lt;R:&nbsp;<a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Read.html" title="trait std::io::Read">Read</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>R</span><span class="where fmt-newline">impl&lt;W:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, '_&gt; <a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a> for <a class="primitive" href="../primitive.reference.html">&amp;'_ mut </a>W</span></code></div></div><code id='borrow_mut.v'>fn <a href='../../std/borrow/trait.BorrowMut.html#tymethod.borrow_mut' class='fnname'>borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="../primitive.reference.html">&amp;mut </a>T</code><a class='srclink' href='../../src/core/borrow.rs.html#219' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Mutably borrows from an owned value. <a href="../../std/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></p>
</div></div><h3 id='impl-Any' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/any/trait.Any.html" title="trait std::any::Any">Any</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,&nbsp;</span></code><a href='#impl-Any' class='anchor'></a><a class='srclink' href='../../src/core/any.rs.html#100-102' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='method.type_id' class="method hidden"><code id='type_id.v'>fn <a href='../../std/any/trait.Any.html#tymethod.type_id' class='fnname'>type_id</a>(&amp;self) -&gt; <a class="struct" href="../../std/any/struct.TypeId.html" title="struct std::any::TypeId">TypeId</a></code><a class='srclink' href='../../src/core/any.rs.html#101' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Gets the <code>TypeId</code> of <code>self</code>. <a href="../../std/any/trait.Any.html#tymethod.type_id">Read more</a></p>
</div></div><h3 id='impl-ToOwned' class='impl'><code class='in-band'>impl&lt;T&gt; <a class="trait" href="../../std/borrow/trait.ToOwned.html" title="trait std::borrow::ToOwned">ToOwned</a> for T <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>,&nbsp;</span></code><a href='#impl-ToOwned' class='anchor'></a><a class='srclink' href='../../src/alloc/borrow.rs.html#80-91' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Owned' class="type"><code id='Owned.t'>type <a href='../../std/borrow/trait.ToOwned.html#associatedtype.Owned' class="type">Owned</a> = T</code></h4><h4 id='method.to_owned' class="method hidden"><code id='to_owned.v'>fn <a href='../../std/borrow/trait.ToOwned.html#tymethod.to_owned' class='fnname'>to_owned</a>(&amp;self) -&gt; T</code><a class='srclink' href='../../src/alloc/borrow.rs.html#84-86' title='goto source code'>[src]</a></h4><div class='docblock hidden'><p>Creates owned data from borrowed data, usually by cloning. <a href="../../std/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></p>
</div><h4 id='method.clone_into' class="method hidden"><code id='clone_into.v'>fn <a href='../../std/borrow/trait.ToOwned.html#method.clone_into' class='fnname'>clone_into</a>(&amp;self, target: <a class="primitive" href="../primitive.reference.html">&amp;mut </a>T)</code><a class='srclink' href='../../src/alloc/borrow.rs.html#88-90' title='goto source code'>[src]</a></h4><div class='stability hidden'><div class='stab unstable'><details><summary><span class='emoji'>🔬</span> This is a nightly-only experimental API. (<code>toowned_clone_into</code>&nbsp;<a href="https://github.com/rust-lang/rust/issues/41263">#41263</a>)</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="../../std/borrow/trait.ToOwned.html#method.clone_into">Read more</a></p>
</div></div></div></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g., <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g., <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "std";</script><script src="../../aliases.js"></script><script src="../../main1.35.0.js"></script><script defer src="../../search-index.js"></script></body></html>