Sophie

Sophie

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

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 `HashSet` struct in crate `std`."><meta name="keywords" content="rust, rustlang, rust-lang, HashSet"><title>std::collections::hash_set::HashSet - 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 HashSet</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">contains</a><a href="#method.difference">difference</a><a href="#method.drain">drain</a><a href="#method.get">get</a><a href="#method.hasher">hasher</a><a href="#method.insert">insert</a><a href="#method.intersection">intersection</a><a href="#method.is_disjoint">is_disjoint</a><a href="#method.is_empty">is_empty</a><a href="#method.is_subset">is_subset</a><a href="#method.is_superset">is_superset</a><a href="#method.iter">iter</a><a href="#method.len">len</a><a href="#method.new">new</a><a href="#method.remove">remove</a><a href="#method.replace">replace</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.symmetric_difference">symmetric_difference</a><a href="#method.take">take</a><a href="#method.union">union</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-BitAnd%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E">BitAnd&lt;&amp;&#39;_ HashSet&lt;T, S&gt;&gt;</a><a href="#impl-BitOr%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E">BitOr&lt;&amp;&#39;_ HashSet&lt;T, S&gt;&gt;</a><a href="#impl-BitXor%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E">BitXor&lt;&amp;&#39;_ HashSet&lt;T, S&gt;&gt;</a><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%20T%3E">Extend&lt;&amp;&#39;a T&gt;</a><a href="#impl-Extend%3CT%3E">Extend&lt;T&gt;</a><a href="#impl-FromIterator%3CT%3E">FromIterator&lt;T&gt;</a><a href="#impl-IntoIterator">IntoIterator</a><a href="#impl-PartialEq%3CHashSet%3CT%2C%20S%3E%3E">PartialEq&lt;HashSet&lt;T, S&gt;&gt;</a><a href="#impl-Sub%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E">Sub&lt;&amp;&#39;_ HashSet&lt;T, 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>::<wbr><a href='index.html'>hash_set</a></p><script>window.sidebarCurrent = {name: 'HashSet', 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/set.rs.html#111-113' 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 href='index.html'>hash_set</a>::<wbr><a class="struct" href=''>HashSet</a></span></h1><div class="docblock type-decl hidden-by-usual-hider"><pre class='rust struct'>pub struct HashSet&lt;T, 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 set implemented as a <code>HashMap</code> where the value is <code>()</code>.</p>
<p>As with the <a href="struct.HashMap.html"><code>HashMap</code></a> type, a <code>HashSet</code> requires that the elements
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. 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 an item to be modified in such a way that the
item'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 set. 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>
<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">HashSet</span>;
<span class="comment">// Type inference lets us omit an explicit type signature (which</span>
<span class="comment">// would be `HashSet&lt;String&gt;` in this example).</span>
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">books</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="comment">// Add some books.</span>
<span class="ident">books</span>.<span class="ident">insert</span>(<span class="string">&quot;A Dance With Dragons&quot;</span>.<span class="ident">to_string</span>());
<span class="ident">books</span>.<span class="ident">insert</span>(<span class="string">&quot;To Kill a Mockingbird&quot;</span>.<span class="ident">to_string</span>());
<span class="ident">books</span>.<span class="ident">insert</span>(<span class="string">&quot;The Odyssey&quot;</span>.<span class="ident">to_string</span>());
<span class="ident">books</span>.<span class="ident">insert</span>(<span class="string">&quot;The Great Gatsby&quot;</span>.<span class="ident">to_string</span>());

<span class="comment">// Check for a specific one.</span>
<span class="kw">if</span> <span class="op">!</span><span class="ident">books</span>.<span class="ident">contains</span>(<span class="string">&quot;The Winds of Winter&quot;</span>) {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;We have {} books, but The Winds of Winter ain&#39;t one.&quot;</span>,
             <span class="ident">books</span>.<span class="ident">len</span>());
}

<span class="comment">// Remove a book.</span>
<span class="ident">books</span>.<span class="ident">remove</span>(<span class="string">&quot;The Odyssey&quot;</span>);

<span class="comment">// Iterate over everything.</span>
<span class="kw">for</span> <span class="ident">book</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">books</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">book</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%3AHashSet%3B%0A%2F%2F%20Type%20inference%20lets%20us%20omit%20an%20explicit%20type%20signature%20(which%0A%2F%2F%20would%20be%20%60HashSet%3CString%3E%60%20in%20this%20example).%0Alet%20mut%20books%20%3D%20HashSet%3A%3Anew()%3B%0A%0A%2F%2F%20Add%20some%20books.%0Abooks.insert(%22A%20Dance%20With%20Dragons%22.to_string())%3B%0Abooks.insert(%22To%20Kill%20a%20Mockingbird%22.to_string())%3B%0Abooks.insert(%22The%20Odyssey%22.to_string())%3B%0Abooks.insert(%22The%20Great%20Gatsby%22.to_string())%3B%0A%0A%2F%2F%20Check%20for%20a%20specific%20one.%0Aif%20!books.contains(%22The%20Winds%20of%20Winter%22)%20%7B%0A%20%20%20%20println!(%22We%20have%20%7B%7D%20books%2C%20but%20The%20Winds%20of%20Winter%20ain't%20one.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20books.len())%3B%0A%7D%0A%0A%2F%2F%20Remove%20a%20book.%0Abooks.remove(%22The%20Odyssey%22)%3B%0A%0A%2F%2F%20Iterate%20over%20everything.%0Afor%20book%20in%20%26books%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20book)%3B%0A%7D%0A%7D">Run</a></pre></div>
<p>The easiest way to use <code>HashSet</code> with a custom 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>, this will in the
future be implied by <a href="../../std/cmp/trait.Eq.html"><code>Eq</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">HashSet</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">power</span>: <span class="ident">usize</span>,
}

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">vikings</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span> { <span class="ident">name</span>: <span class="string">&quot;Einar&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">power</span>: <span class="number">9</span> });
<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span> { <span class="ident">name</span>: <span class="string">&quot;Einar&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">power</span>: <span class="number">9</span> });
<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span> { <span class="ident">name</span>: <span class="string">&quot;Olaf&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">power</span>: <span class="number">4</span> });
<span class="ident">vikings</span>.<span class="ident">insert</span>(<span class="ident">Viking</span> { <span class="ident">name</span>: <span class="string">&quot;Harald&quot;</span>.<span class="ident">to_string</span>(), <span class="ident">power</span>: <span class="number">8</span> });

<span class="comment">// Use derived implementation to print the vikings.</span>
<span class="kw">for</span> <span class="ident">x</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;{:?}&quot;</span>, <span class="ident">x</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%3AHashSet%3B%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%20power%3A%20usize%2C%0A%7D%0A%0Alet%20mut%20vikings%20%3D%20HashSet%3A%3Anew()%3B%0A%0Avikings.insert(Viking%20%7B%20name%3A%20%22Einar%22.to_string()%2C%20power%3A%209%20%7D)%3B%0Avikings.insert(Viking%20%7B%20name%3A%20%22Einar%22.to_string()%2C%20power%3A%209%20%7D)%3B%0Avikings.insert(Viking%20%7B%20name%3A%20%22Olaf%22.to_string()%2C%20power%3A%204%20%7D)%3B%0Avikings.insert(Viking%20%7B%20name%3A%20%22Harald%22.to_string()%2C%20power%3A%208%20%7D)%3B%0A%0A%2F%2F%20Use%20derived%20implementation%20to%20print%20the%20vikings.%0Afor%20x%20in%20%26vikings%20%7B%0A%20%20%20%20println!(%22%7B%3A%3F%7D%22%2C%20x)%3B%0A%7D%0A%7D">Run</a></pre></div>
<p>A <code>HashSet</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">HashSet</span>;

<span class="kw">fn</span> <span class="ident">main</span>() {
    <span class="kw">let</span> <span class="ident">viking_names</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw-2">&amp;</span><span class="lifetime">&#39;static</span> <span class="ident">str</span><span class="op">&gt;</span> <span class="op">=</span>
        [ <span class="string">&quot;Einar&quot;</span>, <span class="string">&quot;Olaf&quot;</span>, <span class="string">&quot;Harald&quot;</span> ].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
    <span class="comment">// use the values stored in the set</span>
}<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=%23!%5Ballow(unused)%5D%0Ause%20std%3A%3Acollections%3A%3AHashSet%3B%0A%0Afn%20main()%20%7B%0A%20%20%20%20let%20viking_names%3A%20HashSet%3C%26'static%20str%3E%20%3D%0A%20%20%20%20%20%20%20%20%5B%20%22Einar%22%2C%20%22Olaf%22%2C%20%22Harald%22%20%5D.iter().cloned().collect()%3B%0A%20%20%20%20%2F%2F%20use%20the%20values%20stored%20in%20the%20set%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;T:&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>&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, <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/set.rs.html#115-150' 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, <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/set.rs.html#129-131' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashSet</code>.</p>
<p>The hash set 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">HashSet</span>;
<span class="kw">let</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashSet</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%3AHashSet%3B%0Alet%20set%3A%20HashSet%3Ci32%3E%20%3D%20HashSet%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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, <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/set.rs.html#147-149' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashSet</code> with the specified capacity.</p>
<p>The hash set will be able to hold at least <code>capacity</code> elements without
reallocating. If <code>capacity</code> is 0, the hash set 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">HashSet</span>;
<span class="kw">let</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">capacity</span>() <span class="op">&gt;=</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%3AHashSet%3B%0Alet%20set%3A%20HashSet%3Ci32%3E%20%3D%20HashSet%3A%3Awith_capacity(10)%3B%0Aassert!(set.capacity()%20%3E%3D%2010)%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-1' class='impl'><code class='in-band'>impl&lt;T, S&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a href='#impl-1' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#152-262' 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/set.rs.html#164-166' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the number of elements the set can hold without reallocating.</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">HashSet</span>;
<span class="kw">let</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</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%3AHashSet%3B%0Alet%20set%3A%20HashSet%3Ci32%3E%20%3D%20HashSet%3A%3Awith_capacity(100)%3B%0Aassert!(set.capacity()%20%3E%3D%20100)%3B%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_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, K&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, K&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K&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_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, K&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='iter.v'>pub fn <a href='#method.iter' class='fnname'>iter</a>(&amp;self) -&gt; <a class="struct" href="../../../std/collections/hash_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;T&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#185-187' title='goto source code'>[src]</a></h4><div class='docblock'><p>An iterator visiting all elements in arbitrary order.
The iterator element type is <code>&amp;'a T</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">HashSet</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="string">&quot;a&quot;</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>);

<span class="comment">// Will print in an arbitrary order.</span>
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">set</span>.<span class="ident">iter</span>() {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</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%3AHashSet%3B%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0Aset.insert(%22a%22)%3B%0Aset.insert(%22b%22)%3B%0A%0A%2F%2F%20Will%20print%20in%20an%20arbitrary%20order.%0Afor%20x%20in%20set.iter()%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%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/set.rs.html#202-204' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the number of elements in the set.</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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">len</span>(), <span class="number">0</span>);
<span class="ident">v</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">v</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%3AHashSet%3B%0A%0Alet%20mut%20v%20%3D%20HashSet%3A%3Anew()%3B%0Aassert_eq!(v.len()%2C%200)%3B%0Av.insert(1)%3B%0Aassert_eq!(v.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/set.rs.html#219-221' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the set contains no elements.</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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</span>.<span class="ident">is_empty</span>());
<span class="ident">v</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">v</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%3AHashSet%3B%0A%0Alet%20mut%20v%20%3D%20HashSet%3A%3Anew()%3B%0Aassert!(v.is_empty())%3B%0Av.insert(1)%3B%0Aassert!(!v.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_set/struct.Drain.html" title="struct std::collections::hash_set::Drain">Drain</a>&lt;'a, K&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Drain.html" title="struct std::collections::hash_set::Drain">Drain</a>&lt;'a, K&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K&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_set/struct.Drain.html" title="struct std::collections::hash_set::Drain">Drain</a>&lt;'a, K&gt;</span><span class="where fmt-newline">    type <a href='../../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = K;</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_set/struct.Drain.html" title="struct std::collections::hash_set::Drain">Drain</a>&lt;T&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/set.rs.html#242-244' title='goto source code'>[src]</a></h4><div class='docblock'><p>Clears the set, returning all elements in an iterator.</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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">set</span>.<span class="ident">is_empty</span>());

<span class="comment">// print 1, 2, 3 in an arbitrary order</span>
<span class="kw">for</span> <span class="ident">i</span> <span class="kw">in</span> <span class="ident">set</span>.<span class="ident">drain</span>() {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">i</span>);
}

<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</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%3AHashSet%3B%0A%0Alet%20mut%20set%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Aassert!(!set.is_empty())%3B%0A%0A%2F%2F%20print%201%2C%202%2C%203%20in%20an%20arbitrary%20order%0Afor%20i%20in%20set.drain()%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20i)%3B%0A%7D%0A%0Aassert!(set.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/set.rs.html#259-261' title='goto source code'>[src]</a></h4><div class='docblock'><p>Clears the set, removing all values.</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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">v</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="ident">v</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="ident">v</span>.<span class="ident">clear</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">v</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%3AHashSet%3B%0A%0Alet%20mut%20v%20%3D%20HashSet%3A%3Anew()%3B%0Av.insert(1)%3B%0Av.clear()%3B%0Aassert!(v.is_empty())%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-2' class='impl'><code class='in-band'>impl&lt;T, S&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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/set.rs.html#264-780' 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>(hasher: S) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, 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/set.rs.html#290-292' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates a new empty hash set which will use the given hasher to hash
keys.</p>
<p>The hash set is also created with the default initial capacity.</p>
<p>Warning: <code>hasher</code> is normally randomly generated, and
is designed to allow <code>HashSet</code>s 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-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">HashSet</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">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">with_hasher</span>(<span class="ident">s</span>);
<span class="ident">set</span>.<span class="ident">insert</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%3AHashSet%3B%0Ause%20std%3A%3Acollections%3A%3Ahash_map%3A%3ARandomState%3B%0A%0Alet%20s%20%3D%20RandomState%3A%3Anew()%3B%0Alet%20mut%20set%20%3D%20HashSet%3A%3Awith_hasher(s)%3B%0Aset.insert(2)%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>(capacity: <a class="primitive" href="../../primitive.usize.html">usize</a>, hasher: S) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, 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/set.rs.html#317-319' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashSet</code> with the specified capacity, using
<code>hasher</code> to hash the keys.</p>
<p>The hash set will be able to hold at least <code>capacity</code> elements without
reallocating. If <code>capacity</code> is 0, the hash set will not allocate.</p>
<p>Warning: <code>hasher</code> is normally randomly generated, and
is designed to allow <code>HashSet</code>s 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-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">HashSet</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">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">with_capacity_and_hasher</span>(<span class="number">10</span>, <span class="ident">s</span>);
<span class="ident">set</span>.<span class="ident">insert</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%3AHashSet%3B%0Ause%20std%3A%3Acollections%3A%3Ahash_map%3A%3ARandomState%3B%0A%0Alet%20s%20%3D%20RandomState%3A%3Anew()%3B%0Alet%20mut%20set%20%3D%20HashSet%3A%3Awith_capacity_and_hasher(10%2C%20s)%3B%0Aset.insert(1)%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/set.rs.html#336-338' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a reference to the set's <a href="../../std/hash/trait.BuildHasher.html"><code>BuildHasher</code></a>.</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">HashSet</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">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashSet</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">set</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%3AHashSet%3B%0Ause%20std%3A%3Acollections%3A%3Ahash_map%3A%3ARandomState%3B%0A%0Alet%20hasher%20%3D%20RandomState%3A%3Anew()%3B%0Alet%20set%3A%20HashSet%3Ci32%3E%20%3D%20HashSet%3A%3Awith_hasher(hasher)%3B%0Alet%20hasher%3A%20%26RandomState%20%3D%20set.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/set.rs.html#357-359' 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>HashSet</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 <code>usize</code>.</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">HashSet</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="ident">set</span>.<span class="ident">reserve</span>(<span class="number">10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">capacity</span>() <span class="op">&gt;=</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%3AHashSet%3B%0Alet%20mut%20set%3A%20HashSet%3Ci32%3E%20%3D%20HashSet%3A%3Anew()%3B%0Aset.reserve(10)%3B%0Aassert!(set.capacity()%20%3E%3D%2010)%3B%0A%7D">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/set.rs.html#378-380' title='goto source code'>[src]</a></h4><div class='docblock'><p>Shrinks the capacity of the set 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-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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">capacity</span>() <span class="op">&gt;=</span> <span class="number">100</span>);
<span class="ident">set</span>.<span class="ident">shrink_to_fit</span>();
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</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%3AHashSet%3B%0A%0Alet%20mut%20set%20%3D%20HashSet%3A%3Awith_capacity(100)%3B%0Aset.insert(1)%3B%0Aset.insert(2)%3B%0Aassert!(set.capacity()%20%3E%3D%20100)%3B%0Aset.shrink_to_fit()%3B%0Aassert!(set.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/set.rs.html#406-408' 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 set 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-14" class="section-header"><a href="#examples-14">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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">with_capacity</span>(<span class="number">100</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">capacity</span>() <span class="op">&gt;=</span> <span class="number">100</span>);
<span class="ident">set</span>.<span class="ident">shrink_to</span>(<span class="number">10</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">capacity</span>() <span class="op">&gt;=</span> <span class="number">10</span>);
<span class="ident">set</span>.<span class="ident">shrink_to</span>(<span class="number">0</span>);
<span class="macro">assert</span><span class="macro">!</span>(<span class="ident">set</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%3AHashSet%3B%0A%0Alet%20mut%20set%20%3D%20HashSet%3A%3Awith_capacity(100)%3B%0Aset.insert(1)%3B%0Aset.insert(2)%3B%0Aassert!(set.capacity()%20%3E%3D%20100)%3B%0Aset.shrink_to(10)%3B%0Aassert!(set.capacity()%20%3E%3D%2010)%3B%0Aset.shrink_to(0)%3B%0Aassert!(set.capacity()%20%3E%3D%202)%3B%0A%7D&amp;version=nightly">Run</a></pre></div>
</div><h4 id='method.difference' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Difference.html" title="struct std::collections::hash_set::Difference">Difference</a>&lt;'a, T, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Difference.html" title="struct std::collections::hash_set::Difference">Difference</a>&lt;'a, T, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T, S&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_set/struct.Difference.html" title="struct std::collections::hash_set::Difference">Difference</a>&lt;'a, T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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></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>T;</span></code></div></div><code id='difference.v'>pub fn <a href='#method.difference' class='fnname'>difference</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self, <br>&nbsp;&nbsp;&nbsp;&nbsp;other: &amp;'a <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;<br>) -&gt; <a class="struct" href="../../../std/collections/hash_set/struct.Difference.html" title="struct std::collections::hash_set::Difference">Difference</a>&lt;'a, T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#434-439' title='goto source code'>[src]</a></h4><div class='docblock'><p>Visits the values representing the difference,
i.e., the values that are in <code>self</code> but not in <code>other</code>.</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">HashSet</span>;
<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();

<span class="comment">// Can be seen as `a - b`.</span>
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">a</span>.<span class="ident">difference</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>) {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</span>); <span class="comment">// Print 1</span>
}

<span class="kw">let</span> <span class="ident">diff</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">difference</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">diff</span>, [<span class="number">1</span>].<span class="ident">iter</span>().<span class="ident">collect</span>());

<span class="comment">// Note that difference is not symmetric,</span>
<span class="comment">// and `b - a` means something else:</span>
<span class="kw">let</span> <span class="ident">diff</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">b</span>.<span class="ident">difference</span>(<span class="kw-2">&amp;</span><span class="ident">a</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">diff</span>, [<span class="number">4</span>].<span class="ident">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%3AHashSet%3B%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20%5B4%2C%202%2C%203%2C%204%5D.iter().cloned().collect()%3B%0A%0A%2F%2F%20Can%20be%20seen%20as%20%60a%20-%20b%60.%0Afor%20x%20in%20a.difference(%26b)%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%20%2F%2F%20Print%201%0A%7D%0A%0Alet%20diff%3A%20HashSet%3C_%3E%20%3D%20a.difference(%26b).collect()%3B%0Aassert_eq!(diff%2C%20%5B1%5D.iter().collect())%3B%0A%0A%2F%2F%20Note%20that%20difference%20is%20not%20symmetric%2C%0A%2F%2F%20and%20%60b%20-%20a%60%20means%20something%20else%3A%0Alet%20diff%3A%20HashSet%3C_%3E%20%3D%20b.difference(%26a).collect()%3B%0Aassert_eq!(diff%2C%20%5B4%5D.iter().collect())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.symmetric_difference' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.SymmetricDifference.html" title="struct std::collections::hash_set::SymmetricDifference">SymmetricDifference</a>&lt;'a, T, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.SymmetricDifference.html" title="struct std::collections::hash_set::SymmetricDifference">SymmetricDifference</a>&lt;'a, T, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T, S&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_set/struct.SymmetricDifference.html" title="struct std::collections::hash_set::SymmetricDifference">SymmetricDifference</a>&lt;'a, T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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></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>T;</span></code></div></div><code id='symmetric_difference.v'>pub fn <a href='#method.symmetric_difference' class='fnname'>symmetric_difference</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self, <br>&nbsp;&nbsp;&nbsp;&nbsp;other: &amp;'a <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;<br>) -&gt; <a class="struct" href="../../../std/collections/hash_set/struct.SymmetricDifference.html" title="struct std::collections::hash_set::SymmetricDifference">SymmetricDifference</a>&lt;'a, T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#463-467' title='goto source code'>[src]</a></h4><div class='docblock'><p>Visits the values representing the symmetric difference,
i.e., the values that are in <code>self</code> or in <code>other</code> but not in both.</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">HashSet</span>;
<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();

<span class="comment">// Print 1, 4 in arbitrary order.</span>
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">a</span>.<span class="ident">symmetric_difference</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>) {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</span>);
}

<span class="kw">let</span> <span class="ident">diff1</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">symmetric_difference</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>).<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">diff2</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">b</span>.<span class="ident">symmetric_difference</span>(<span class="kw-2">&amp;</span><span class="ident">a</span>).<span class="ident">collect</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">diff1</span>, <span class="ident">diff2</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">diff1</span>, [<span class="number">1</span>, <span class="number">4</span>].<span class="ident">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%3AHashSet%3B%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20%5B4%2C%202%2C%203%2C%204%5D.iter().cloned().collect()%3B%0A%0A%2F%2F%20Print%201%2C%204%20in%20arbitrary%20order.%0Afor%20x%20in%20a.symmetric_difference(%26b)%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A%0Alet%20diff1%3A%20HashSet%3C_%3E%20%3D%20a.symmetric_difference(%26b).collect()%3B%0Alet%20diff2%3A%20HashSet%3C_%3E%20%3D%20b.symmetric_difference(%26a).collect()%3B%0A%0Aassert_eq!(diff1%2C%20diff2)%3B%0Aassert_eq!(diff1%2C%20%5B1%2C%204%5D.iter().collect())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.intersection' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Intersection.html" title="struct std::collections::hash_set::Intersection">Intersection</a>&lt;'a, T, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Intersection.html" title="struct std::collections::hash_set::Intersection">Intersection</a>&lt;'a, T, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T, S&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_set/struct.Intersection.html" title="struct std::collections::hash_set::Intersection">Intersection</a>&lt;'a, T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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></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>T;</span></code></div></div><code id='intersection.v'>pub fn <a href='#method.intersection' class='fnname'>intersection</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self, <br>&nbsp;&nbsp;&nbsp;&nbsp;other: &amp;'a <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;<br>) -&gt; <a class="struct" href="../../../std/collections/hash_set/struct.Intersection.html" title="struct std::collections::hash_set::Intersection">Intersection</a>&lt;'a, T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#488-500' title='goto source code'>[src]</a></h4><div class='docblock'><p>Visits the values representing the intersection,
i.e., the values that are both in <code>self</code> and <code>other</code>.</p>
<h1 id="examples-17" class="section-header"><a href="#examples-17">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">HashSet</span>;
<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();

<span class="comment">// Print 2, 3 in arbitrary order.</span>
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">a</span>.<span class="ident">intersection</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>) {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</span>);
}

<span class="kw">let</span> <span class="ident">intersection</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">intersection</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">intersection</span>, [<span class="number">2</span>, <span class="number">3</span>].<span class="ident">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%3AHashSet%3B%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20%5B4%2C%202%2C%203%2C%204%5D.iter().cloned().collect()%3B%0A%0A%2F%2F%20Print%202%2C%203%20in%20arbitrary%20order.%0Afor%20x%20in%20a.intersection(%26b)%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A%0Alet%20intersection%3A%20HashSet%3C_%3E%20%3D%20a.intersection(%26b).collect()%3B%0Aassert_eq!(intersection%2C%20%5B2%2C%203%5D.iter().collect())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.union' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Union.html" title="struct std::collections::hash_set::Union">Union</a>&lt;'a, T, S&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Union.html" title="struct std::collections::hash_set::Union">Union</a>&lt;'a, T, S&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, T, S&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_set/struct.Union.html" title="struct std::collections::hash_set::Union">Union</a>&lt;'a, T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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></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>T;</span></code></div></div><code id='union.v'>pub fn <a href='#method.union' class='fnname'>union</a>&lt;'a&gt;(&amp;'a self, other: &amp;'a <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="struct" href="../../../std/collections/hash_set/struct.Union.html" title="struct std::collections::hash_set::Union">Union</a>&lt;'a, T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#521-531' title='goto source code'>[src]</a></h4><div class='docblock'><p>Visits the values representing the union,
i.e., all the values in <code>self</code> or <code>other</code>, without duplicates.</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">HashSet</span>;
<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">4</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();

<span class="comment">// Print 1, 2, 3, 4 in arbitrary order.</span>
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="ident">a</span>.<span class="ident">union</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>) {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</span>);
}

<span class="kw">let</span> <span class="ident">union</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">a</span>.<span class="ident">union</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>).<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">union</span>, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].<span class="ident">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%3AHashSet%3B%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20%5B4%2C%202%2C%203%2C%204%5D.iter().cloned().collect()%3B%0A%0A%2F%2F%20Print%201%2C%202%2C%203%2C%204%20in%20arbitrary%20order.%0Afor%20x%20in%20a.union(%26b)%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A%0Alet%20union%3A%20HashSet%3C_%3E%20%3D%20a.union(%26b).collect()%3B%0Aassert_eq!(union%2C%20%5B1%2C%202%2C%203%2C%204%5D.iter().collect())%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.contains' class="method"><code id='contains.v'>pub fn <a href='#method.contains' class='fnname'>contains</a>&lt;Q:&nbsp;?<a class="trait" href="../../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;self, value: <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;T: <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/set.rs.html#552-557' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the set contains a value.</p>
<p>The value may be any borrowed form of the set's value 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 value type.</p>
<h1 id="examples-19" class="section-header"><a href="#examples-19">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">HashSet</span>;

<span class="kw">let</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">contains</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">set</span>.<span class="ident">contains</span>(<span class="kw-2">&amp;</span><span class="number">4</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%3AHashSet%3B%0A%0Alet%20set%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Aassert_eq!(set.contains(%261)%2C%20true)%3B%0Aassert_eq!(set.contains(%264)%2C%20false)%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, value: <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>T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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.9.0'>1.9.0</div><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#578-583' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns a reference to the value in the set, if any, that is equal to the given value.</p>
<p>The value may be any borrowed form of the set's value 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 value type.</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">HashSet</span>;

<span class="kw">let</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">get</span>(<span class="kw-2">&amp;</span><span class="number">2</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">get</span>(<span class="kw-2">&amp;</span><span class="number">4</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%3AHashSet%3B%0A%0Alet%20set%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Aassert_eq!(set.get(%262)%2C%20Some(%262))%3B%0Aassert_eq!(set.get(%264)%2C%20None)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.is_disjoint' class="method"><code id='is_disjoint.v'>pub fn <a href='#method.is_disjoint' class='fnname'>is_disjoint</a>(&amp;self, other: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="primitive" href="../../primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#603-609' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if <code>self</code> has no elements in common with <code>other</code>.
This is equivalent to checking for an empty intersection.</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">HashSet</span>;

<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">b</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_disjoint</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>), <span class="bool-val">true</span>);
<span class="ident">b</span>.<span class="ident">insert</span>(<span class="number">4</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_disjoint</span>(<span class="kw-2">&amp;</span><span class="ident">b</span>), <span class="bool-val">true</span>);
<span class="ident">b</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">a</span>.<span class="ident">is_disjoint</span>(<span class="kw-2">&amp;</span><span class="ident">b</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%3AHashSet%3B%0A%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Alet%20mut%20b%20%3D%20HashSet%3A%3Anew()%3B%0A%0Aassert_eq!(a.is_disjoint(%26b)%2C%20true)%3B%0Ab.insert(4)%3B%0Aassert_eq!(a.is_disjoint(%26b)%2C%20true)%3B%0Ab.insert(1)%3B%0Aassert_eq!(a.is_disjoint(%26b)%2C%20false)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.is_subset' class="method"><code id='is_subset.v'>pub fn <a href='#method.is_subset' class='fnname'>is_subset</a>(&amp;self, other: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="primitive" href="../../primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#629-635' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the set is a subset of another,
i.e., <code>other</code> contains at least all the values in <code>self</code>.</p>
<h1 id="examples-22" class="section-header"><a href="#examples-22">Examples</a></h1>
<div class="example-wrap"><pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">collections</span>::<span class="ident">HashSet</span>;

<span class="kw">let</span> <span class="ident">sup</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">is_subset</span>(<span class="kw-2">&amp;</span><span class="ident">sup</span>), <span class="bool-val">true</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">is_subset</span>(<span class="kw-2">&amp;</span><span class="ident">sup</span>), <span class="bool-val">true</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">4</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">is_subset</span>(<span class="kw-2">&amp;</span><span class="ident">sup</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%3AHashSet%3B%0A%0Alet%20sup%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0A%0Aassert_eq!(set.is_subset(%26sup)%2C%20true)%3B%0Aset.insert(2)%3B%0Aassert_eq!(set.is_subset(%26sup)%2C%20true)%3B%0Aset.insert(4)%3B%0Aassert_eq!(set.is_subset(%26sup)%2C%20false)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.is_superset' class="method"><code id='is_superset.v'>pub fn <a href='#method.is_superset' class='fnname'>is_superset</a>(&amp;self, other: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="primitive" href="../../primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#659-661' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns <code>true</code> if the set is a superset of another,
i.e., <code>self</code> contains at least all the values in <code>other</code>.</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">HashSet</span>;

<span class="kw">let</span> <span class="ident">sub</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">is_superset</span>(<span class="kw-2">&amp;</span><span class="ident">sub</span>), <span class="bool-val">false</span>);

<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">0</span>);
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">1</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">is_superset</span>(<span class="kw-2">&amp;</span><span class="ident">sub</span>), <span class="bool-val">false</span>);

<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">is_superset</span>(<span class="kw-2">&amp;</span><span class="ident">sub</span>), <span class="bool-val">true</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%3AHashSet%3B%0A%0Alet%20sub%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%5D.iter().cloned().collect()%3B%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0A%0Aassert_eq!(set.is_superset(%26sub)%2C%20false)%3B%0A%0Aset.insert(0)%3B%0Aset.insert(1)%3B%0Aassert_eq!(set.is_superset(%26sub)%2C%20false)%3B%0A%0Aset.insert(2)%3B%0Aassert_eq!(set.is_superset(%26sub)%2C%20true)%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, value: T) -&gt; <a class="primitive" href="../../primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#681-683' title='goto source code'>[src]</a></h4><div class='docblock'><p>Adds a value to the set.</p>
<p>If the set did not have this value present, <code>true</code> is returned.</p>
<p>If the set did have this value present, <code>false</code> is returned.</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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>), <span class="bool-val">true</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>), <span class="bool-val">false</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</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%3AHashSet%3B%0A%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0A%0Aassert_eq!(set.insert(2)%2C%20true)%3B%0Aassert_eq!(set.insert(2)%2C%20false)%3B%0Aassert_eq!(set.len()%2C%201)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.replace' class="method"><code id='replace.v'>pub fn <a href='#method.replace' class='fnname'>replace</a>(&amp;mut self, value: T) -&gt; <a class="enum" href="../../../std/option/enum.Option.html" title="enum std::option::Option">Option</a>&lt;T&gt;</code><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#701-703' title='goto source code'>[src]</a></h4><div class='docblock'><p>Adds a value to the set, replacing the existing value, if any, that is equal to the given
one. Returns the replaced value.</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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="ident">Vec</span>::<span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span>::<span class="ident">new</span>());

<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">get</span>(<span class="kw-2">&amp;</span>[][..]).<span class="ident">unwrap</span>().<span class="ident">capacity</span>(), <span class="number">0</span>);
<span class="ident">set</span>.<span class="ident">replace</span>(<span class="ident">Vec</span>::<span class="ident">with_capacity</span>(<span class="number">10</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">get</span>(<span class="kw-2">&amp;</span>[][..]).<span class="ident">unwrap</span>().<span class="ident">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%3AHashSet%3B%0A%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0Aset.insert(Vec%3A%3A%3Ci32%3E%3A%3Anew())%3B%0A%0Aassert_eq!(set.get(%26%5B%5D%5B..%5D).unwrap().capacity()%2C%200)%3B%0Aset.replace(Vec%3A%3Awith_capacity(10))%3B%0Aassert_eq!(set.get(%26%5B%5D%5B..%5D).unwrap().capacity()%2C%2010)%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, value: <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;T: <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/set.rs.html#727-732' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes a value from the set. Returns whether the value was
present in the set.</p>
<p>The value may be any borrowed form of the set's value 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 value 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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();

<span class="ident">set</span>.<span class="ident">insert</span>(<span class="number">2</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">remove</span>(<span class="kw-2">&amp;</span><span class="number">2</span>), <span class="bool-val">true</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">remove</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%3AHashSet%3B%0A%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0A%0Aset.insert(2)%3B%0Aassert_eq!(set.remove(%262)%2C%20true)%3B%0Aassert_eq!(set.remove(%262)%2C%20false)%3B%0A%7D">Run</a></pre></div>
</div><h4 id='method.take' class="method"><code id='take.v'>pub fn <a href='#method.take' class='fnname'>take</a>&lt;Q:&nbsp;?<a class="trait" href="../../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>&gt;(&amp;mut self, value: <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;T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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.9.0'>1.9.0</div><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#753-758' title='goto source code'>[src]</a></h4><div class='docblock'><p>Removes and returns the value in the set, if any, that is equal to the given one.</p>
<p>The value may be any borrowed form of the set's value 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 value 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">HashSet</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">take</span>(<span class="kw-2">&amp;</span><span class="number">2</span>), <span class="prelude-val">Some</span>(<span class="number">2</span>));
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">set</span>.<span class="ident">take</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%3AHashSet%3B%0A%0Alet%20mut%20set%3A%20HashSet%3C_%3E%20%3D%20%5B1%2C%202%2C%203%5D.iter().cloned().collect()%3B%0Aassert_eq!(set.take(%262)%2C%20Some(2))%3B%0Aassert_eq!(set.take(%262)%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>T) -&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/set.rs.html#775-779' 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 elements <code>e</code> such that <code>f(&amp;e)</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">HashSet</span>;

<span class="kw">let</span> <span class="ident">xs</span> <span class="op">=</span> [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>,<span class="number">6</span>];
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="ident">i32</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">xs</span>.<span class="ident">iter</span>().<span class="ident">cloned</span>().<span class="ident">collect</span>();
<span class="ident">set</span>.<span class="ident">retain</span>(<span class="op">|</span><span class="kw-2">&amp;</span><span class="ident">k</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">set</span>.<span class="ident">len</span>(), <span class="number">3</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%3AHashSet%3B%0A%0Alet%20xs%20%3D%20%5B1%2C2%2C3%2C4%2C5%2C6%5D%3B%0Alet%20mut%20set%3A%20HashSet%3Ci32%3E%20%3D%20xs.iter().cloned().collect()%3B%0Aset.retain(%7C%26k%7C%20k%20%25%202%20%3D%3D%200)%3B%0Aassert_eq!(set.len()%2C%203)%3B%0A%7D">Run</a></pre></div>
</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;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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;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/set.rs.html#804-811' 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/set.rs.html#808-810' 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%3CHashSet%3CT%2C%20S%3E%3E' class='impl'><code class='in-band'>impl&lt;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;&gt; for <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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-PartialEq%3CHashSet%3CT%2C%20S%3E%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#783-794' 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="primitive" href="../../primitive.bool.html">bool</a></code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#787-793' 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;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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-Eq' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#797-801' title='goto source code'>[src]</a></h3><div class='impl-items'></div><h3 id='impl-Sub%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='impl'><code class='in-band'>impl&lt;T, S, '_, '_&gt; <a class="trait" href="../../../std/ops/trait.Sub.html" title="trait std::ops::Sub">Sub</a>&lt;&amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;&gt; for &amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</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-Sub%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#953-982' 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.Sub.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code></h4><div class='docblock'><p>The resulting type after applying the <code>-</code> operator.</p>
</div><h4 id='method.sub' class="method"><code id='sub.v'>fn <a href='../../../std/ops/trait.Sub.html#tymethod.sub' class='fnname'>sub</a>(self, rhs: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#979-981' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the difference of <code>self</code> and <code>rhs</code> as a new <code>HashSet&lt;T, S&gt;</code>.</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">HashSet</span>;

<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();

<span class="kw">let</span> <span class="ident">set</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">a</span> <span class="op">-</span> <span class="kw-2">&amp;</span><span class="ident">b</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">i</span> <span class="op">=</span> <span class="number">0</span>;
<span class="kw">let</span> <span class="ident">expected</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>];
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">set</span> {
    <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">expected</span>.<span class="ident">contains</span>(<span class="ident">x</span>));
    <span class="ident">i</span> <span class="op">+=</span> <span class="number">1</span>;
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">i</span>, <span class="ident">expected</span>.<span class="ident">len</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%3AHashSet%3B%0A%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20vec!%5B1%2C%202%2C%203%5D.into_iter().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20vec!%5B3%2C%204%2C%205%5D.into_iter().collect()%3B%0A%0Alet%20set%20%3D%20%26a%20-%20%26b%3B%0A%0Alet%20mut%20i%20%3D%200%3B%0Alet%20expected%20%3D%20%5B1%2C%202%5D%3B%0Afor%20x%20in%20%26set%20%7B%0A%20%20%20%20assert!(expected.contains(x))%3B%0A%20%20%20%20i%20%2B%3D%201%3B%0A%7D%0Aassert_eq!(i%2C%20expected.len())%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-BitAnd%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='impl'><code class='in-band'>impl&lt;T, S, '_, '_&gt; <a class="trait" href="../../../std/ops/trait.BitAnd.html" title="trait std::ops::BitAnd">BitAnd</a>&lt;&amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;&gt; for &amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</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-BitAnd%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#889-918' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Output-1' class="type"><code id='Output.t-1'>type <a href='../../../std/ops/trait.BitAnd.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code></h4><div class='docblock'><p>The resulting type after applying the <code>&amp;</code> operator.</p>
</div><h4 id='method.bitand' class="method"><code id='bitand.v'>fn <a href='../../../std/ops/trait.BitAnd.html#tymethod.bitand' class='fnname'>bitand</a>(self, rhs: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#915-917' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the intersection of <code>self</code> and <code>rhs</code> as a new <code>HashSet&lt;T, S&gt;</code>.</p>
<h1 id="examples-30" class="section-header"><a href="#examples-30">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">HashSet</span>;

<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();

<span class="kw">let</span> <span class="ident">set</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">a</span> <span class="op">&amp;</span> <span class="kw-2">&amp;</span><span class="ident">b</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">i</span> <span class="op">=</span> <span class="number">0</span>;
<span class="kw">let</span> <span class="ident">expected</span> <span class="op">=</span> [<span class="number">2</span>, <span class="number">3</span>];
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">set</span> {
    <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">expected</span>.<span class="ident">contains</span>(<span class="ident">x</span>));
    <span class="ident">i</span> <span class="op">+=</span> <span class="number">1</span>;
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">i</span>, <span class="ident">expected</span>.<span class="ident">len</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%3AHashSet%3B%0A%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20vec!%5B1%2C%202%2C%203%5D.into_iter().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20vec!%5B2%2C%203%2C%204%5D.into_iter().collect()%3B%0A%0Alet%20set%20%3D%20%26a%20%26%20%26b%3B%0A%0Alet%20mut%20i%20%3D%200%3B%0Alet%20expected%20%3D%20%5B2%2C%203%5D%3B%0Afor%20x%20in%20%26set%20%7B%0A%20%20%20%20assert!(expected.contains(x))%3B%0A%20%20%20%20i%20%2B%3D%201%3B%0A%7D%0Aassert_eq!(i%2C%20expected.len())%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-BitOr%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='impl'><code class='in-band'>impl&lt;T, S, '_, '_&gt; <a class="trait" href="../../../std/ops/trait.BitOr.html" title="trait std::ops::BitOr">BitOr</a>&lt;&amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;&gt; for &amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</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-BitOr%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#857-886' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Output-2' class="type"><code id='Output.t-2'>type <a href='../../../std/ops/trait.BitOr.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code></h4><div class='docblock'><p>The resulting type after applying the <code>|</code> operator.</p>
</div><h4 id='method.bitor' class="method"><code id='bitor.v'>fn <a href='../../../std/ops/trait.BitOr.html#tymethod.bitor' class='fnname'>bitor</a>(self, rhs: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#883-885' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the union of <code>self</code> and <code>rhs</code> as a new <code>HashSet&lt;T, S&gt;</code>.</p>
<h1 id="examples-31" class="section-header"><a href="#examples-31">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">HashSet</span>;

<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();

<span class="kw">let</span> <span class="ident">set</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">a</span> <span class="op">|</span> <span class="kw-2">&amp;</span><span class="ident">b</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">i</span> <span class="op">=</span> <span class="number">0</span>;
<span class="kw">let</span> <span class="ident">expected</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">set</span> {
    <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">expected</span>.<span class="ident">contains</span>(<span class="ident">x</span>));
    <span class="ident">i</span> <span class="op">+=</span> <span class="number">1</span>;
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">i</span>, <span class="ident">expected</span>.<span class="ident">len</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%3AHashSet%3B%0A%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20vec!%5B1%2C%202%2C%203%5D.into_iter().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20vec!%5B3%2C%204%2C%205%5D.into_iter().collect()%3B%0A%0Alet%20set%20%3D%20%26a%20%7C%20%26b%3B%0A%0Alet%20mut%20i%20%3D%200%3B%0Alet%20expected%20%3D%20%5B1%2C%202%2C%203%2C%204%2C%205%5D%3B%0Afor%20x%20in%20%26set%20%7B%0A%20%20%20%20assert!(expected.contains(x))%3B%0A%20%20%20%20i%20%2B%3D%201%3B%0A%7D%0Aassert_eq!(i%2C%20expected.len())%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-BitXor%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='impl'><code class='in-band'>impl&lt;T, S, '_, '_&gt; <a class="trait" href="../../../std/ops/trait.BitXor.html" title="trait std::ops::BitXor">BitXor</a>&lt;&amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;&gt; for &amp;'_ <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</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-BitXor%3C%26%27_%20HashSet%3CT%2C%20S%3E%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#921-950' title='goto source code'>[src]</a></h3><div class='impl-items'><h4 id='associatedtype.Output-3' class="type"><code id='Output.t-3'>type <a href='../../../std/ops/trait.BitXor.html#associatedtype.Output' class="type">Output</a> = <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code></h4><div class='docblock'><p>The resulting type after applying the <code>^</code> operator.</p>
</div><h4 id='method.bitxor' class="method"><code id='bitxor.v'>fn <a href='../../../std/ops/trait.BitXor.html#tymethod.bitxor' class='fnname'>bitxor</a>(self, rhs: &amp;<a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#947-949' title='goto source code'>[src]</a></h4><div class='docblock'><p>Returns the symmetric difference of <code>self</code> and <code>rhs</code> as a new <code>HashSet&lt;T, S&gt;</code>.</p>
<h1 id="examples-32" class="section-header"><a href="#examples-32">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">HashSet</span>;

<span class="kw">let</span> <span class="ident">a</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();
<span class="kw">let</span> <span class="ident">b</span>: <span class="ident">HashSet</span><span class="op">&lt;</span><span class="kw">_</span><span class="op">&gt;</span> <span class="op">=</span> <span class="macro">vec</span><span class="macro">!</span>[<span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>].<span class="ident">into_iter</span>().<span class="ident">collect</span>();

<span class="kw">let</span> <span class="ident">set</span> <span class="op">=</span> <span class="kw-2">&amp;</span><span class="ident">a</span> <span class="op">^</span> <span class="kw-2">&amp;</span><span class="ident">b</span>;

<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">i</span> <span class="op">=</span> <span class="number">0</span>;
<span class="kw">let</span> <span class="ident">expected</span> <span class="op">=</span> [<span class="number">1</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">5</span>];
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">set</span> {
    <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">expected</span>.<span class="ident">contains</span>(<span class="ident">x</span>));
    <span class="ident">i</span> <span class="op">+=</span> <span class="number">1</span>;
}
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">i</span>, <span class="ident">expected</span>.<span class="ident">len</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%3AHashSet%3B%0A%0Alet%20a%3A%20HashSet%3C_%3E%20%3D%20vec!%5B1%2C%202%2C%203%5D.into_iter().collect()%3B%0Alet%20b%3A%20HashSet%3C_%3E%20%3D%20vec!%5B3%2C%204%2C%205%5D.into_iter().collect()%3B%0A%0Alet%20set%20%3D%20%26a%20%5E%20%26b%3B%0A%0Alet%20mut%20i%20%3D%200%3B%0Alet%20expected%20%3D%20%5B1%2C%202%2C%204%2C%205%5D%3B%0Afor%20x%20in%20%26set%20%7B%0A%20%20%20%20assert!(expected.contains(x))%3B%0A%20%20%20%20i%20%2B%3D%201%3B%0A%7D%0Aassert_eq!(i%2C%20expected.len())%3B%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-FromIterator%3CT%3E' class='impl'><code class='in-band'>impl&lt;T, S&gt; <a class="trait" href="../../../std/iter/trait.FromIterator.html" title="trait std::iter::FromIterator">FromIterator</a>&lt;T&gt; for <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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%3CT%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#814-823' 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;I:&nbsp;<a class="trait" href="../../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a>&lt;Item = T&gt;&gt;(iter: I) -&gt; <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#818-822' 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, T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a href='#impl-IntoIterator' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#1075-1082' 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.reference.html">&amp;'a </a>T</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_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, T&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_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, K&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, K&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'a, K&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_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, K&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='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_set/struct.Iter.html" title="struct std::collections::hash_set::Iter">Iter</a>&lt;'a, T&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#1079-1081' 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;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a href='#impl-IntoIterator-1' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#1085-1112' 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> = T</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_set/struct.IntoIter.html" title="struct std::collections::hash_set::IntoIter">IntoIter</a>&lt;T&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"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.IntoIter.html" title="struct std::collections::hash_set::IntoIter">IntoIter</a>&lt;K&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../../../std/collections/hash_set/struct.IntoIter.html" title="struct std::collections::hash_set::IntoIter">IntoIter</a>&lt;K&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;K&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_set/struct.IntoIter.html" title="struct std::collections::hash_set::IntoIter">IntoIter</a>&lt;K&gt;</span><span class="where fmt-newline">    type <a href='../../../std/iter/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = K;</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_set/struct.IntoIter.html" title="struct std::collections::hash_set::IntoIter">IntoIter</a>&lt;T&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#1109-1111' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates a consuming iterator, that is, one that moves each value out
of the set in arbitrary order. The set cannot be used after calling
this.</p>
<h1 id="examples-33" class="section-header"><a href="#examples-33">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">HashSet</span>;
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">set</span> <span class="op">=</span> <span class="ident">HashSet</span>::<span class="ident">new</span>();
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="string">&quot;a&quot;</span>.<span class="ident">to_string</span>());
<span class="ident">set</span>.<span class="ident">insert</span>(<span class="string">&quot;b&quot;</span>.<span class="ident">to_string</span>());

<span class="comment">// Not possible to collect to a Vec&lt;String&gt; with a regular `.iter()`.</span>
<span class="kw">let</span> <span class="ident">v</span>: <span class="ident">Vec</span><span class="op">&lt;</span><span class="ident">String</span><span class="op">&gt;</span> <span class="op">=</span> <span class="ident">set</span>.<span class="ident">into_iter</span>().<span class="ident">collect</span>();

<span class="comment">// Will print in an arbitrary order.</span>
<span class="kw">for</span> <span class="ident">x</span> <span class="kw">in</span> <span class="kw-2">&amp;</span><span class="ident">v</span> {
    <span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{}&quot;</span>, <span class="ident">x</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%3AHashSet%3B%0Alet%20mut%20set%20%3D%20HashSet%3A%3Anew()%3B%0Aset.insert(%22a%22.to_string())%3B%0Aset.insert(%22b%22.to_string())%3B%0A%0A%2F%2F%20Not%20possible%20to%20collect%20to%20a%20Vec%3CString%3E%20with%20a%20regular%20%60.iter()%60.%0Alet%20v%3A%20Vec%3CString%3E%20%3D%20set.into_iter().collect()%3B%0A%0A%2F%2F%20Will%20print%20in%20an%20arbitrary%20order.%0Afor%20x%20in%20%26v%20%7B%0A%20%20%20%20println!(%22%7B%7D%22%2C%20x)%3B%0A%7D%0A%7D">Run</a></pre></div>
</div></div><h3 id='impl-Extend%3CT%3E' class='impl'><code class='in-band'>impl&lt;T, S&gt; <a class="trait" href="../../../std/iter/trait.Extend.html" title="trait std::iter::Extend">Extend</a>&lt;T&gt; for <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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%3CT%3E' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#826-833' 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;I:&nbsp;<a class="trait" href="../../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a>&lt;Item = T&gt;&gt;(&amp;mut self, iter: I)</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#830-832' 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%20T%3E' class='impl'><code class='in-band'>impl&lt;'a, T, S&gt; <a class="trait" href="../../../std/iter/trait.Extend.html" title="trait std::iter::Extend">Extend</a>&lt;<a class="primitive" href="../../primitive.reference.html">&amp;'a </a>T&gt; for <a class="struct" href="../../../std/collections/struct.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'a + <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;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%20T%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/set.rs.html#836-843' 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;I:&nbsp;<a class="trait" href="../../../std/iter/trait.IntoIterator.html" title="trait std::iter::IntoIterator">IntoIterator</a>&lt;Item = <a class="primitive" href="../../primitive.reference.html">&amp;'a </a>T&gt;&gt;(&amp;mut self, iter: I)</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#840-842' 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;T:&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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a href='#impl-Clone' class='anchor'></a><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#109' 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#109' 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;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <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/set.rs.html#846-854' 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt;</code><a class='srclink' href='../../../src/std/collections/hash/set.rs.html#851-853' title='goto source code'>[src]</a></h4><div class='docblock'><p>Creates an empty <code>HashSet&lt;T, 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;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<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;T: <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;T, 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.HashSet.html" title="struct std::collections::HashSet">HashSet</a>&lt;T, S&gt; <span class="where fmt-newline">where<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;T: <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-2' 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-2' 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-2' class="type"><code id='Item.t-2'>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-2' class="type"><code id='IntoIter.t-2'>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-2' class="method hidden"><code id='into_iter.v-2'>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>