Files
google-apis-rs/slab/struct.Slab.html
2024-03-05 21:06:01 +01:00

460 lines
90 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="Pre-allocated storage for a uniform data type"><title>Slab in slab - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-ac92e1bbe349e143.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="slab" data-themes="" data-resource-suffix="" data-rustdoc-version="1.76.0 (07dca489a 2024-02-04)" data-channel="1.76.0" data-search-js="search-2b6ce74ff89ae146.js" data-settings-js="settings-4313503d2e1961c2.js" ><script src="../static.files/storage-f2adc0d6ca4d09fb.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-305769736d49e732.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-feafe1bb7466e4bd.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../slab/index.html">slab</a><span class="version">0.4.9</span></h2></div><h2 class="location"><a href="#">Slab</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.capacity">capacity</a></li><li><a href="#method.clear">clear</a></li><li><a href="#method.compact">compact</a></li><li><a href="#method.contains">contains</a></li><li><a href="#method.drain">drain</a></li><li><a href="#method.get">get</a></li><li><a href="#method.get2_mut">get2_mut</a></li><li><a href="#method.get2_unchecked_mut">get2_unchecked_mut</a></li><li><a href="#method.get_mut">get_mut</a></li><li><a href="#method.get_unchecked">get_unchecked</a></li><li><a href="#method.get_unchecked_mut">get_unchecked_mut</a></li><li><a href="#method.insert">insert</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.iter">iter</a></li><li><a href="#method.iter_mut">iter_mut</a></li><li><a href="#method.key_of">key_of</a></li><li><a href="#method.len">len</a></li><li><a href="#method.new">new</a></li><li><a href="#method.remove">remove</a></li><li><a href="#method.reserve">reserve</a></li><li><a href="#method.reserve_exact">reserve_exact</a></li><li><a href="#method.retain">retain</a></li><li><a href="#method.shrink_to_fit">shrink_to_fit</a></li><li><a href="#method.try_remove">try_remove</a></li><li><a href="#method.vacant_entry">vacant_entry</a></li><li><a href="#method.vacant_key">vacant_key</a></li><li><a href="#method.with_capacity">with_capacity</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Clone-for-Slab%3CT%3E">Clone</a></li><li><a href="#impl-Debug-for-Slab%3CT%3E">Debug</a></li><li><a href="#impl-Default-for-Slab%3CT%3E">Default</a></li><li><a href="#impl-FromIterator%3C(usize,+T)%3E-for-Slab%3CT%3E">FromIterator&lt;(usize, T)&gt;</a></li><li><a href="#impl-Index%3Cusize%3E-for-Slab%3CT%3E">Index&lt;usize&gt;</a></li><li><a href="#impl-IndexMut%3Cusize%3E-for-Slab%3CT%3E">IndexMut&lt;usize&gt;</a></li><li><a href="#impl-IntoIterator-for-%26Slab%3CT%3E">IntoIterator</a></li><li><a href="#impl-IntoIterator-for-%26mut+Slab%3CT%3E">IntoIterator</a></li><li><a href="#impl-IntoIterator-for-Slab%3CT%3E">IntoIterator</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-Slab%3CT%3E">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Slab%3CT%3E">Send</a></li><li><a href="#impl-Sync-for-Slab%3CT%3E">Sync</a></li><li><a href="#impl-Unpin-for-Slab%3CT%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-Slab%3CT%3E">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-T">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-T">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-T">Into&lt;U&gt;</a></li><li><a href="#impl-ToOwned-for-T">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-T">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In crate slab</a></h2></div></nav><div class="sidebar-resizer"></div>
<main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><div id="sidebar-button" tabindex="-1"><a href="../slab/all.html" title="show sidebar"></a></div><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press S to search, ? for more options…" type="search"><div id="help-button" tabindex="-1"><a href="../help.html" title="help">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Struct <a href="index.html">slab</a>::<wbr><a class="struct" href="#">Slab</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="src" href="../src/slab/lib.rs.html#132-142">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>&#x2212;</span>]</button></span></div><pre class="rust item-decl"><code>pub struct Slab&lt;T&gt; { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Pre-allocated storage for a uniform data type</p>
<p>See the <a href="index.html">module documentation</a> for more details.</p>
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#236-1201">source</a><a href="#impl-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#251-257">source</a><h4 class="code-header">pub const fn <a href="#method.new" class="fn">new</a>() -&gt; Self</h4></section></summary><div class="docblock"><p>Construct a new, empty <code>Slab</code>.</p>
<p>The function does not allocate and the returned slab will have no
capacity until <code>insert</code> is called or capacity is explicitly reserved.</p>
<p>This is <code>const fn</code> on Rust 1.39+.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>slab: Slab&lt;i32&gt; = Slab::new();</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.with_capacity" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#300-306">source</a><h4 class="code-header">pub fn <a href="#method.with_capacity" class="fn">with_capacity</a>(capacity: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h4></section></summary><div class="docblock"><p>Construct a new, empty <code>Slab</code> with the specified capacity.</p>
<p>The returned slab will be able to store exactly <code>capacity</code> without
reallocating. If <code>capacity</code> is 0, the slab will not allocate.</p>
<p>It is important to note that this function does not specify the <em>length</em>
of the returned slab, but only the capacity. For an explanation of the
difference between length and capacity, see <a href="index.html#capacity-and-reallocation">Capacity and
reallocation</a>.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::with_capacity(<span class="number">10</span>);
<span class="comment">// The slab contains no values, even though it has capacity for more
</span><span class="macro">assert_eq!</span>(slab.len(), <span class="number">0</span>);
<span class="comment">// These are all done without reallocating...
</span><span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">10 </span>{
slab.insert(i);
}
<span class="comment">// ...but this may make the slab reallocate
</span>slab.insert(<span class="number">11</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.capacity" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#317-319">source</a><h4 class="code-header">pub fn <a href="#method.capacity" class="fn">capacity</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Return the number of values the slab can store without reallocating.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span>slab: Slab&lt;i32&gt; = Slab::with_capacity(<span class="number">10</span>);
<span class="macro">assert_eq!</span>(slab.capacity(), <span class="number">10</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.reserve" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#347-353">source</a><h4 class="code-header">pub fn <a href="#method.reserve" class="fn">reserve</a>(&amp;mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Reserve capacity for at least <code>additional</code> more values to be stored
without allocating.</p>
<p><code>reserve</code> does nothing if the slab already has sufficient capacity for
<code>additional</code> more values. If more capacity is required, a new segment of
memory will be allocated and all existing values will be copied into it.
As such, if the slab is already very large, a call to <code>reserve</code> can end
up being expensive.</p>
<p>The slab may reserve more than <code>additional</code> extra space in order to
avoid frequent reallocations. Use <code>reserve_exact</code> instead to guarantee
that only the requested space is allocated.</p>
<h5 id="panics"><a href="#panics">Panics</a></h5>
<p>Panics if the new capacity exceeds <code>isize::MAX</code> bytes.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
slab.insert(<span class="string">"hello"</span>);
slab.reserve(<span class="number">10</span>);
<span class="macro">assert!</span>(slab.capacity() &gt;= <span class="number">11</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.reserve_exact" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#381-387">source</a><h4 class="code-header">pub fn <a href="#method.reserve_exact" class="fn">reserve_exact</a>(&amp;mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Reserve the minimum capacity required to store exactly <code>additional</code>
more values.</p>
<p><code>reserve_exact</code> does nothing if the slab already has sufficient capacity
for <code>additional</code> more values. If more capacity is required, a new segment
of memory will be allocated and all existing values will be copied into
it. As such, if the slab is already very large, a call to <code>reserve</code> can
end up being expensive.</p>
<p>Note that the allocator may give the slab more space than it requests.
Therefore capacity can not be relied upon to be precisely minimal.
Prefer <code>reserve</code> if future insertions are expected.</p>
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
<p>Panics if the new capacity exceeds <code>isize::MAX</code> bytes.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
slab.insert(<span class="string">"hello"</span>);
slab.reserve_exact(<span class="number">10</span>);
<span class="macro">assert!</span>(slab.capacity() &gt;= <span class="number">11</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.shrink_to_fit" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#430-455">source</a><h4 class="code-header">pub fn <a href="#method.shrink_to_fit" class="fn">shrink_to_fit</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Shrink the capacity of the slab as much as possible without invalidating keys.</p>
<p>Because values cannot be moved to a different index, the slab cannot
shrink past any stored values.
It will drop down as close as possible to the length but the allocator may
still inform the underlying vector that there is space for a few more elements.</p>
<p>This function can take O(n) time even when the capacity cannot be reduced
or the allocation is shrunk in place. Repeated calls run in O(1) though.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::with_capacity(<span class="number">10</span>);
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">3 </span>{
slab.insert(i);
}
slab.shrink_to_fit();
<span class="macro">assert!</span>(slab.capacity() &gt;= <span class="number">3 </span>&amp;&amp; slab.capacity() &lt; <span class="number">10</span>);</code></pre></div>
<p>The slab cannot shrink past the last present value even if previous
values are removed:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::with_capacity(<span class="number">10</span>);
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">4 </span>{
slab.insert(i);
}
slab.remove(<span class="number">0</span>);
slab.remove(<span class="number">3</span>);
slab.shrink_to_fit();
<span class="macro">assert!</span>(slab.capacity() &gt;= <span class="number">3 </span>&amp;&amp; slab.capacity() &lt; <span class="number">10</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.compact" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#523-576">source</a><h4 class="code-header">pub fn <a href="#method.compact" class="fn">compact</a>&lt;F&gt;(&amp;mut self, rekey: F)<div class="where">where
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Reduce the capacity as much as possible, changing the key for elements when necessary.</p>
<p>To allow updating references to the elements which must be moved to a new key,
this function takes a closure which is called before moving each element.
The second and third parameters to the closure are the current key and
new key respectively.
In case changing the key for one element turns out not to be possible,
the move can be cancelled by returning <code>false</code> from the closure.
In that case no further attempts at relocating elements is made.
If the closure unwinds, the slab will be left in a consistent state,
but the value that the closure panicked on might be removed.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::with_capacity(<span class="number">10</span>);
<span class="kw">let </span>a = slab.insert(<span class="string">'a'</span>);
slab.insert(<span class="string">'b'</span>);
slab.insert(<span class="string">'c'</span>);
slab.remove(a);
slab.compact(|<span class="kw-2">&amp;mut </span>value, from, to| {
<span class="macro">assert_eq!</span>((value, from, to), (<span class="string">'c'</span>, <span class="number">2</span>, <span class="number">0</span>));
<span class="bool-val">true
</span>});
<span class="macro">assert!</span>(slab.capacity() &gt;= <span class="number">2 </span>&amp;&amp; slab.capacity() &lt; <span class="number">10</span>);</code></pre></div>
<p>The value is not moved when the closure returns <code>Err</code>:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::with_capacity(<span class="number">100</span>);
<span class="kw">let </span>a = slab.insert(<span class="string">'a'</span>);
<span class="kw">let </span>b = slab.insert(<span class="string">'b'</span>);
slab.remove(a);
slab.compact(|<span class="kw-2">&amp;mut </span>value, from, to| <span class="bool-val">false</span>);
<span class="macro">assert_eq!</span>(slab.iter().next(), <span class="prelude-val">Some</span>((b, <span class="kw-2">&amp;</span><span class="string">'b'</span>)));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.clear" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#593-597">source</a><h4 class="code-header">pub fn <a href="#method.clear" class="fn">clear</a>(&amp;mut self)</h4></section></summary><div class="docblock"><p>Clear the slab of all values.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">3 </span>{
slab.insert(i);
}
slab.clear();
<span class="macro">assert!</span>(slab.is_empty());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.len" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#613-615">source</a><h4 class="code-header">pub fn <a href="#method.len" class="fn">len</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Return the number of stored values.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">3 </span>{
slab.insert(i);
}
<span class="macro">assert_eq!</span>(<span class="number">3</span>, slab.len());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.is_empty" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#629-631">source</a><h4 class="code-header">pub fn <a href="#method.is_empty" class="fn">is_empty</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Return <code>true</code> if there are no values stored in the slab.</p>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="macro">assert!</span>(slab.is_empty());
slab.insert(<span class="number">1</span>);
<span class="macro">assert!</span>(!slab.is_empty());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.iter" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#657-662">source</a><h4 class="code-header">pub fn <a href="#method.iter" class="fn">iter</a>(&amp;self) -&gt; <a class="struct" href="struct.Iter.html" title="struct slab::Iter">Iter</a>&lt;'_, T&gt; <a href="#" class="tooltip" data-notable-ty="Iter&lt;&#39;_, T&gt;"></a></h4></section></summary><div class="docblock"><p>Return an iterator over the slab.</p>
<p>This function should generally be <strong>avoided</strong> as it is not efficient.
Iterators must iterate over every slot in the slab even if it is
vacant. As such, a slab with a capacity of 1 million but only one
stored value must still iterate the million slots.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..<span class="number">3 </span>{
slab.insert(i);
}
<span class="kw">let </span><span class="kw-2">mut </span>iterator = slab.iter();
<span class="macro">assert_eq!</span>(iterator.next(), <span class="prelude-val">Some</span>((<span class="number">0</span>, <span class="kw-2">&amp;</span><span class="number">0</span>)));
<span class="macro">assert_eq!</span>(iterator.next(), <span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="kw-2">&amp;</span><span class="number">1</span>)));
<span class="macro">assert_eq!</span>(iterator.next(), <span class="prelude-val">Some</span>((<span class="number">2</span>, <span class="kw-2">&amp;</span><span class="number">2</span>)));
<span class="macro">assert_eq!</span>(iterator.next(), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.iter_mut" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#689-694">source</a><h4 class="code-header">pub fn <a href="#method.iter_mut" class="fn">iter_mut</a>(&amp;mut self) -&gt; <a class="struct" href="struct.IterMut.html" title="struct slab::IterMut">IterMut</a>&lt;'_, T&gt; <a href="#" class="tooltip" data-notable-ty="IterMut&lt;&#39;_, T&gt;"></a></h4></section></summary><div class="docblock"><p>Return an iterator that allows modifying each value.</p>
<p>This function should generally be <strong>avoided</strong> as it is not efficient.
Iterators must iterate over every slot in the slab even if it is
vacant. As such, a slab with a capacity of 1 million but only one
stored value must still iterate the million slots.</p>
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key1 = slab.insert(<span class="number">0</span>);
<span class="kw">let </span>key2 = slab.insert(<span class="number">1</span>);
<span class="kw">for </span>(key, val) <span class="kw">in </span>slab.iter_mut() {
<span class="kw">if </span>key == key1 {
<span class="kw-2">*</span>val += <span class="number">2</span>;
}
}
<span class="macro">assert_eq!</span>(slab[key1], <span class="number">2</span>);
<span class="macro">assert_eq!</span>(slab[key2], <span class="number">1</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.get" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#711-716">source</a><h4 class="code-header">pub fn <a href="#method.get" class="fn">get</a>(&amp;self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;T</a>&gt;</h4></section></summary><div class="docblock"><p>Return a reference to the value associated with the given key.</p>
<p>If the given key is not associated with a value, then <code>None</code> is
returned.</p>
<h5 id="examples-12"><a href="#examples-12">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="string">"hello"</span>);
<span class="macro">assert_eq!</span>(slab.get(key), <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="string">"hello"</span>));
<span class="macro">assert_eq!</span>(slab.get(<span class="number">123</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.get_mut" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#735-740">source</a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fn">get_mut</a>(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>&gt;</h4></section></summary><div class="docblock"><p>Return a mutable reference to the value associated with the given key.</p>
<p>If the given key is not associated with a value, then <code>None</code> is
returned.</p>
<h5 id="examples-13"><a href="#examples-13">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="string">"hello"</span>);
<span class="kw-2">*</span>slab.get_mut(key).unwrap() = <span class="string">"world"</span>;
<span class="macro">assert_eq!</span>(slab[key], <span class="string">"world"</span>);
<span class="macro">assert_eq!</span>(slab.get_mut(<span class="number">123</span>), <span class="prelude-val">None</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.get2_mut" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#769-791">source</a><h4 class="code-header">pub fn <a href="#method.get2_mut" class="fn">get2_mut</a>(&amp;mut self, key1: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, key2: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>)&gt;</h4></section></summary><div class="docblock"><p>Return two mutable references to the values associated with the two
given keys simultaneously.</p>
<p>If any one of the given keys is not associated with a value, then <code>None</code>
is returned.</p>
<p>This function can be used to get two mutable references out of one slab,
so that you can manipulate both of them at the same time, eg. swap them.</p>
<h5 id="panics-2"><a href="#panics-2">Panics</a></h5>
<p>This function will panic if <code>key1</code> and <code>key2</code> are the same.</p>
<h5 id="examples-14"><a href="#examples-14">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::mem;
<span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key1 = slab.insert(<span class="number">1</span>);
<span class="kw">let </span>key2 = slab.insert(<span class="number">2</span>);
<span class="kw">let </span>(value1, value2) = slab.get2_mut(key1, key2).unwrap();
mem::swap(value1, value2);
<span class="macro">assert_eq!</span>(slab[key1], <span class="number">2</span>);
<span class="macro">assert_eq!</span>(slab[key2], <span class="number">1</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.get_unchecked" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#815-820">source</a><h4 class="code-header">pub unsafe fn <a href="#method.get_unchecked" class="fn">get_unchecked</a>(&amp;self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;T</a></h4></section></summary><div class="docblock"><p>Return a reference to the value associated with the given key without
performing bounds checking.</p>
<p>For a safe alternative see <a href="struct.Slab.html#method.get" title="method slab::Slab::get"><code>get</code></a>.</p>
<p>This function should be used with care.</p>
<h5 id="safety"><a href="#safety">Safety</a></h5>
<p>The key must be within bounds.</p>
<h5 id="examples-15"><a href="#examples-15">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="number">2</span>);
<span class="kw">unsafe </span>{
<span class="macro">assert_eq!</span>(slab.get_unchecked(key), <span class="kw-2">&amp;</span><span class="number">2</span>);
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.get_unchecked_mut" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#847-852">source</a><h4 class="code-header">pub unsafe fn <a href="#method.get_unchecked_mut" class="fn">get_unchecked_mut</a>(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a></h4></section></summary><div class="docblock"><p>Return a mutable reference to the value associated with the given key
without performing bounds checking.</p>
<p>For a safe alternative see <a href="struct.Slab.html#method.get_mut" title="method slab::Slab::get_mut"><code>get_mut</code></a>.</p>
<p>This function should be used with care.</p>
<h5 id="safety-1"><a href="#safety-1">Safety</a></h5>
<p>The key must be within bounds.</p>
<h5 id="examples-16"><a href="#examples-16">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="number">2</span>);
<span class="kw">unsafe </span>{
<span class="kw">let </span>val = slab.get_unchecked_mut(key);
<span class="kw-2">*</span>val = <span class="number">13</span>;
}
<span class="macro">assert_eq!</span>(slab[key], <span class="number">13</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.get2_unchecked_mut" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#881-892">source</a><h4 class="code-header">pub unsafe fn <a href="#method.get2_unchecked_mut" class="fn">get2_unchecked_mut</a>(
&amp;mut self,
key1: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>,
key2: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>
) -&gt; (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>)</h4></section></summary><div class="docblock"><p>Return two mutable references to the values associated with the two
given keys simultaneously without performing bounds checking and safety
condition checking.</p>
<p>For a safe alternative see <a href="struct.Slab.html#method.get2_mut" title="method slab::Slab::get2_mut"><code>get2_mut</code></a>.</p>
<p>This function should be used with care.</p>
<h5 id="safety-2"><a href="#safety-2">Safety</a></h5>
<ul>
<li>Both keys must be within bounds.</li>
<li>The condition <code>key1 != key2</code> must hold.</li>
</ul>
<h5 id="examples-17"><a href="#examples-17">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::mem;
<span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key1 = slab.insert(<span class="number">1</span>);
<span class="kw">let </span>key2 = slab.insert(<span class="number">2</span>);
<span class="kw">let </span>(value1, value2) = <span class="kw">unsafe </span>{ slab.get2_unchecked_mut(key1, key2) };
mem::swap(value1, value2);
<span class="macro">assert_eq!</span>(slab[key1], <span class="number">2</span>);
<span class="macro">assert_eq!</span>(slab[key2], <span class="number">1</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.key_of" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#930-944">source</a><h4 class="code-header">pub fn <a href="#method.key_of" class="fn">key_of</a>(&amp;self, present_element: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;T</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Get the key for an element in the slab.</p>
<p>The reference must point to an element owned by the slab.
Otherwise this function will panic.
This is a constant-time operation because the key can be calculated
from the reference with pointer arithmetic.</p>
<h5 id="panics-3"><a href="#panics-3">Panics</a></h5>
<p>This function will panic if the reference does not point to an element
of the slab.</p>
<h5 id="examples-18"><a href="#examples-18">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(String::from(<span class="string">"foo"</span>));
<span class="kw">let </span>value = <span class="kw-2">&amp;</span>slab[key];
<span class="macro">assert_eq!</span>(slab.key_of(value), key);</code></pre></div>
<p>Values are not compared, so passing a reference to a different location
will result in a panic:</p>
<div class="example-wrap should_panic"><a href="#" class="tooltip" title="This example panics"></a><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="number">0</span>);
<span class="kw">let </span>bad = <span class="kw-2">&amp;</span><span class="number">0</span>;
slab.key_of(bad); <span class="comment">// this will panic
</span><span class="macro">unreachable!</span>();</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.insert" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#964-970">source</a><h4 class="code-header">pub fn <a href="#method.insert" class="fn">insert</a>(&amp;mut self, val: T) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Insert a value in the slab, returning key assigned to the value.</p>
<p>The returned key can later be used to retrieve or remove the value using indexed
lookup and <code>remove</code>. Additional capacity is allocated if needed. See
<a href="index.html#capacity-and-reallocation">Capacity and reallocation</a>.</p>
<h5 id="panics-4"><a href="#panics-4">Panics</a></h5>
<p>Panics if the new storage in the vector exceeds <code>isize::MAX</code> bytes.</p>
<h5 id="examples-19"><a href="#examples-19">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>key = slab.insert(<span class="string">"hello"</span>);
<span class="macro">assert_eq!</span>(slab[key], <span class="string">"hello"</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.vacant_key" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#992-994">source</a><h4 class="code-header">pub fn <a href="#method.vacant_key" class="fn">vacant_key</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the key of the next vacant entry.</p>
<p>This function returns the key of the vacant entry which will be used
for the next insertion. This is equivalent to
<code>slab.vacant_entry().key()</code>, but it doesnt require mutable access.</p>
<h5 id="examples-20"><a href="#examples-20">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="macro">assert_eq!</span>(slab.vacant_key(), <span class="number">0</span>);
slab.insert(<span class="number">0</span>);
<span class="macro">assert_eq!</span>(slab.vacant_key(), <span class="number">1</span>);
slab.insert(<span class="number">1</span>);
slab.remove(<span class="number">0</span>);
<span class="macro">assert_eq!</span>(slab.vacant_key(), <span class="number">0</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.vacant_entry" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#1019-1024">source</a><h4 class="code-header">pub fn <a href="#method.vacant_entry" class="fn">vacant_entry</a>(&amp;mut self) -&gt; <a class="struct" href="struct.VacantEntry.html" title="struct slab::VacantEntry">VacantEntry</a>&lt;'_, T&gt;</h4></section></summary><div class="docblock"><p>Return a handle to a vacant entry allowing for further manipulation.</p>
<p>This function is useful when creating values that must contain their
slab key. The returned <code>VacantEntry</code> reserves a slot in the slab and is
able to query the associated key.</p>
<h5 id="examples-21"><a href="#examples-21">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>hello = {
<span class="kw">let </span>entry = slab.vacant_entry();
<span class="kw">let </span>key = entry.key();
entry.insert((key, <span class="string">"hello"</span>));
key
};
<span class="macro">assert_eq!</span>(hello, slab[hello].<span class="number">0</span>);
<span class="macro">assert_eq!</span>(<span class="string">"hello"</span>, slab[hello].<span class="number">1</span>);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_remove" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#1058-1076">source</a><h4 class="code-header">pub fn <a href="#method.try_remove" class="fn">try_remove</a>(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;T&gt;</h4></section></summary><div class="docblock"><p>Tries to remove the value associated with the given key,
returning the value if the key existed.</p>
<p>The key is then released and may be associated with future stored
values.</p>
<h5 id="examples-22"><a href="#examples-22">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>hello = slab.insert(<span class="string">"hello"</span>);
<span class="macro">assert_eq!</span>(slab.try_remove(hello), <span class="prelude-val">Some</span>(<span class="string">"hello"</span>));
<span class="macro">assert!</span>(!slab.contains(hello));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.remove" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#1099-1101">source</a><h4 class="code-header">pub fn <a href="#method.remove" class="fn">remove</a>(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; T</h4></section></summary><div class="docblock"><p>Remove and return the value associated with the given key.</p>
<p>The key is then released and may be associated with future stored
values.</p>
<h5 id="panics-5"><a href="#panics-5">Panics</a></h5>
<p>Panics if <code>key</code> is not associated with a value.</p>
<h5 id="examples-23"><a href="#examples-23">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>hello = slab.insert(<span class="string">"hello"</span>);
<span class="macro">assert_eq!</span>(slab.remove(hello), <span class="string">"hello"</span>);
<span class="macro">assert!</span>(!slab.contains(hello));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.contains" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#1118-1123">source</a><h4 class="code-header">pub fn <a href="#method.contains" class="fn">contains</a>(&amp;self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Return <code>true</code> if a value is associated with the given key.</p>
<h5 id="examples-24"><a href="#examples-24">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>hello = slab.insert(<span class="string">"hello"</span>);
<span class="macro">assert!</span>(slab.contains(hello));
slab.remove(hello);
<span class="macro">assert!</span>(!slab.contains(hello));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.retain" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#1149-1163">source</a><h4 class="code-header">pub fn <a href="#method.retain" class="fn">retain</a>&lt;F&gt;(&amp;mut self, f: F)<div class="where">where
F: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Retain only the elements specified by the predicate.</p>
<p>In other words, remove all elements <code>e</code> such that <code>f(usize, &amp;mut e)</code>
returns false. This method operates in place and preserves the key
associated with the retained values.</p>
<h5 id="examples-25"><a href="#examples-25">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let </span>k1 = slab.insert(<span class="number">0</span>);
<span class="kw">let </span>k2 = slab.insert(<span class="number">1</span>);
<span class="kw">let </span>k3 = slab.insert(<span class="number">2</span>);
slab.retain(|key, val| key == k1 || <span class="kw-2">*</span>val == <span class="number">1</span>);
<span class="macro">assert!</span>(slab.contains(k1));
<span class="macro">assert!</span>(slab.contains(k2));
<span class="macro">assert!</span>(!slab.contains(k3));
<span class="macro">assert_eq!</span>(<span class="number">2</span>, slab.len());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.drain" class="method"><a class="src rightside" href="../src/slab/lib.rs.html#1192-1200">source</a><h4 class="code-header">pub fn <a href="#method.drain" class="fn">drain</a>(&amp;mut self) -&gt; <a class="struct" href="struct.Drain.html" title="struct slab::Drain">Drain</a>&lt;'_, T&gt; <a href="#" class="tooltip" data-notable-ty="Drain&lt;&#39;_, T&gt;"></a></h4></section></summary><div class="docblock"><p>Return a draining iterator that removes all elements from the slab and
yields the removed items.</p>
<p>Note: Elements are removed even if the iterator is only partially
consumed or not consumed at all.</p>
<h5 id="examples-26"><a href="#examples-26">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">let </span><span class="kw-2">mut </span>slab = Slab::new();
<span class="kw">let _ </span>= slab.insert(<span class="number">0</span>);
<span class="kw">let _ </span>= slab.insert(<span class="number">1</span>);
<span class="kw">let _ </span>= slab.insert(<span class="number">2</span>);
{
<span class="kw">let </span><span class="kw-2">mut </span>drain = slab.drain();
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">0</span>), drain.next());
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">1</span>), drain.next());
<span class="macro">assert_eq!</span>(<span class="prelude-val">Some</span>(<span class="number">2</span>), drain.next());
<span class="macro">assert_eq!</span>(<span class="prelude-val">None</span>, drain.next());
}
<span class="macro">assert!</span>(slab.is_empty());</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Clone-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#144-161">source</a><a href="#impl-Clone-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#148-154">source</a><a href="#method.clone" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html#tymethod.clone" class="fn">clone</a>(&amp;self) -&gt; Self</h4></section></summary><div class='docblock'>Returns a copy of the value. <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#156-160">source</a><a href="#method.clone_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html#method.clone_from" class="fn">clone_from</a>(&amp;mut self, source: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;Self</a>)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1300-1314">source</a><a href="#impl-Debug-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1304-1313">source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&amp;self, fmt: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/1.76.0/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.76.0/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#163-167">source</a><a href="#impl-Default-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.default" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#164-166">source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -&gt; Self</h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.76.0/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-FromIterator%3C(usize,+T)%3E-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1285-1298">source</a><a href="#impl-FromIterator%3C(usize,+T)%3E-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.FromIterator.html" title="trait core::iter::traits::collect::FromIterator">FromIterator</a>&lt;(<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, T)&gt; for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="docblock"><p>Create a slab from an iterator of key-value pairs.</p>
<p>If the iterator produces duplicate keys, the previous value is replaced with the later one.
The keys does not need to be sorted beforehand, and this function always
takes O(n) time.
Note that the returned slab will use space proportional to the largest key,
so dont use <code>Slab</code> with untrusted keys.</p>
<h4 id="examples-27"><a href="#examples-27">Examples</a></h4>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span>vec = <span class="macro">vec!</span>[(<span class="number">2</span>,<span class="string">'a'</span>), (<span class="number">6</span>,<span class="string">'b'</span>), (<span class="number">7</span>,<span class="string">'c'</span>)];
<span class="kw">let </span>slab = vec.into_iter().collect::&lt;Slab&lt;char&gt;&gt;();
<span class="macro">assert_eq!</span>(slab.len(), <span class="number">3</span>);
<span class="macro">assert!</span>(slab.capacity() &gt;= <span class="number">8</span>);
<span class="macro">assert_eq!</span>(slab[<span class="number">2</span>], <span class="string">'a'</span>);</code></pre></div>
<p>With duplicate and unsorted keys:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code>
<span class="kw">let </span>vec = <span class="macro">vec!</span>[(<span class="number">20</span>,<span class="string">'a'</span>), (<span class="number">10</span>,<span class="string">'b'</span>), (<span class="number">11</span>,<span class="string">'c'</span>), (<span class="number">10</span>,<span class="string">'d'</span>)];
<span class="kw">let </span>slab = vec.into_iter().collect::&lt;Slab&lt;char&gt;&gt;();
<span class="macro">assert_eq!</span>(slab.len(), <span class="number">3</span>);
<span class="macro">assert_eq!</span>(slab[<span class="number">10</span>], <span class="string">'d'</span>);</code></pre></div>
</div><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from_iter" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1286-1297">source</a><a href="#method.from_iter" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.FromIterator.html#tymethod.from_iter" class="fn">from_iter</a>&lt;I&gt;(iterable: I) -&gt; Self<div class="where">where
I: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>&lt;Item = (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, T)&gt;,</div></h4></section></summary><div class='docblock'>Creates a value from an iterator. <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.FromIterator.html#tymethod.from_iter">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Index%3Cusize%3E-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1203-1213">source</a><a href="#impl-Index%3Cusize%3E-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html" title="trait core::ops::index::Index">Index</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>&gt; for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl"><a href="#associatedtype.Output" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html#associatedtype.Output" class="associatedtype">Output</a> = T</h4></section></summary><div class='docblock'>The returned type after indexing.</div></details><details class="toggle method-toggle" open><summary><section id="method.index" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1207-1212">source</a><a href="#method.index" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html#tymethod.index" class="fn">index</a>(&amp;self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;T</a></h4></section></summary><div class='docblock'>Performs the indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.Index.html#tymethod.index">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-IndexMut%3Cusize%3E-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1215-1223">source</a><a href="#impl-IndexMut%3Cusize%3E-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.IndexMut.html" title="trait core::ops::index::IndexMut">IndexMut</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>&gt; for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.index_mut" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1217-1222">source</a><a href="#method.index_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.IndexMut.html#tymethod.index_mut" class="fn">index_mut</a>(&amp;mut self, key: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a></h4></section></summary><div class='docblock'>Performs the mutable indexing (<code>container[index]</code>) operation. <a href="https://doc.rust-lang.org/1.76.0/core/ops/index/trait.IndexMut.html#tymethod.index_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-IntoIterator-for-%26Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1237-1244">source</a><a href="#impl-IntoIterator-for-%26Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a, T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for &amp;'a <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Item-2" class="associatedtype trait-impl"><a href="#associatedtype.Item-2" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;'a T</a>)</h4></section></summary><div class='docblock'>The type of the elements being iterated over.</div></details><details class="toggle" open><summary><section id="associatedtype.IntoIter-2" class="associatedtype trait-impl"><a href="#associatedtype.IntoIter-2" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="struct.Iter.html" title="struct slab::Iter">Iter</a>&lt;'a, T&gt;</h4></section></summary><div class='docblock'>Which kind of iterator are we turning this into?</div></details><details class="toggle method-toggle" open><summary><section id="method.into_iter-2" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1241-1243">source</a><a href="#method.into_iter-2" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fn">into_iter</a>(self) -&gt; <a class="struct" href="struct.Iter.html" title="struct slab::Iter">Iter</a>&lt;'a, T&gt; <a href="#" class="tooltip" data-notable-ty="Iter&lt;&#39;a, T&gt;"></a></h4></section></summary><div class='docblock'>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-IntoIterator-for-%26mut+Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1246-1253">source</a><a href="#impl-IntoIterator-for-%26mut+Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a, T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for &amp;'a mut <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Item" class="associatedtype trait-impl"><a href="#associatedtype.Item" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;'a mut T</a>)</h4></section></summary><div class='docblock'>The type of the elements being iterated over.</div></details><details class="toggle" open><summary><section id="associatedtype.IntoIter" class="associatedtype trait-impl"><a href="#associatedtype.IntoIter" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="struct.IterMut.html" title="struct slab::IterMut">IterMut</a>&lt;'a, T&gt;</h4></section></summary><div class='docblock'>Which kind of iterator are we turning this into?</div></details><details class="toggle method-toggle" open><summary><section id="method.into_iter" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1250-1252">source</a><a href="#method.into_iter" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fn">into_iter</a>(self) -&gt; <a class="struct" href="struct.IterMut.html" title="struct slab::IterMut">IterMut</a>&lt;'a, T&gt; <a href="#" class="tooltip" data-notable-ty="IterMut&lt;&#39;a, T&gt;"></a></h4></section></summary><div class='docblock'>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-IntoIterator-for-Slab%3CT%3E" class="impl"><a class="src rightside" href="../src/slab/lib.rs.html#1225-1235">source</a><a href="#impl-IntoIterator-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Item-1" class="associatedtype trait-impl"><a href="#associatedtype.Item-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.Item" class="associatedtype">Item</a> = (<a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.usize.html">usize</a>, T)</h4></section></summary><div class='docblock'>The type of the elements being iterated over.</div></details><details class="toggle" open><summary><section id="associatedtype.IntoIter-1" class="associatedtype trait-impl"><a href="#associatedtype.IntoIter-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#associatedtype.IntoIter" class="associatedtype">IntoIter</a> = <a class="struct" href="struct.IntoIter.html" title="struct slab::IntoIter">IntoIter</a>&lt;T&gt;</h4></section></summary><div class='docblock'>Which kind of iterator are we turning this into?</div></details><details class="toggle method-toggle" open><summary><section id="method.into_iter-1" class="method trait-impl"><a class="src rightside" href="../src/slab/lib.rs.html#1229-1234">source</a><a href="#method.into_iter-1" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter" class="fn">into_iter</a>(self) -&gt; <a class="struct" href="struct.IntoIter.html" title="struct slab::IntoIter">IntoIter</a>&lt;T&gt; <a href="#" class="tooltip" data-notable-ty="IntoIter&lt;T&gt;"></a></h4></section></summary><div class='docblock'>Creates an iterator from a value. <a href="https://doc.rust-lang.org/1.76.0/core/iter/traits/collect/trait.IntoIterator.html#tymethod.into_iter">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-RefUnwindSafe-for-Slab%3CT%3E" class="impl"><a href="#impl-RefUnwindSafe-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a>,</div></h3></section><section id="impl-Send-for-Slab%3CT%3E" class="impl"><a href="#impl-Send-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</div></h3></section><section id="impl-Sync-for-Slab%3CT%3E" class="impl"><a href="#impl-Sync-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,</div></h3></section><section id="impl-Unpin-for-Slab%3CT%3E" class="impl"><a href="#impl-Unpin-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h3></section><section id="impl-UnwindSafe-for-Slab%3CT%3E" class="impl"><a href="#impl-UnwindSafe-for-Slab%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Slab.html" title="struct slab::Slab">Slab</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a>,</div></h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/any.rs.html#140">source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/any.rs.html#141">source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.76.0/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.76.0/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#208">source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#210">source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#216">source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/1.76.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/borrow.rs.html#217">source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.76.0/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#763">source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#766">source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#747-749">source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T<div class="where">where
U: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt;,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#756">source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code><a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ToOwned-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#83-85">source</a><a href="#impl-ToOwned-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#88">source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">to_owned</a>(&amp;self) -&gt; T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/alloc/borrow.rs.html#92">source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fn">clone_into</a>(&amp;self, target: <a class="primitive" href="https://doc.rust-lang.org/1.76.0/std/primitive.reference.html">&amp;mut T</a>)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.76.0/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#803-805">source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T<div class="where">where
U: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;T&gt;,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#810">source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#788-790">source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T<div class="where">where
U: <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.76.0/src/core/convert/mod.rs.html#795">source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.76.0/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.76.0/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div><script type="text/json" id="notable-traits-data">{"Drain<'_, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Drain.html\" title=\"struct slab::Drain\">Drain</a>&lt;'_, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;T&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.Drain.html\" title=\"struct slab::Drain\">Drain</a>&lt;'_, T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = T;</div>","IntoIter<T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.IntoIter.html\" title=\"struct slab::IntoIter\">IntoIter</a>&lt;T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;T&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.IntoIter.html\" title=\"struct slab::IntoIter\">IntoIter</a>&lt;T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = (<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.usize.html\">usize</a>, T);</div>","Iter<'_, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Iter.html\" title=\"struct slab::Iter\">Iter</a>&lt;'a, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'a, T&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.Iter.html\" title=\"struct slab::Iter\">Iter</a>&lt;'a, T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = (<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.usize.html\">usize</a>, <a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.reference.html\">&amp;'a T</a>);</div>","Iter<'a, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.Iter.html\" title=\"struct slab::Iter\">Iter</a>&lt;'a, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'a, T&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.Iter.html\" title=\"struct slab::Iter\">Iter</a>&lt;'a, T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = (<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.usize.html\">usize</a>, <a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.reference.html\">&amp;'a T</a>);</div>","IterMut<'_, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.IterMut.html\" title=\"struct slab::IterMut\">IterMut</a>&lt;'a, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'a, T&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.IterMut.html\" title=\"struct slab::IterMut\">IterMut</a>&lt;'a, T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = (<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.usize.html\">usize</a>, <a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.reference.html\">&amp;'a mut T</a>);</div>","IterMut<'a, T>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.IterMut.html\" title=\"struct slab::IterMut\">IterMut</a>&lt;'a, T&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'a, T&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.IterMut.html\" title=\"struct slab::IterMut\">IterMut</a>&lt;'a, T&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.76.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = (<a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.usize.html\">usize</a>, <a class=\"primitive\" href=\"https://doc.rust-lang.org/1.76.0/std/primitive.reference.html\">&amp;'a mut T</a>);</div>"}</script></section></div></main></body></html>