mirror of
https://github.com/n0-computer/iroh.git
synced 2026-11-28 16:01:09 +00:00
532 lines
106 KiB
HTML
532 lines
106 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A collection of HTTP request handlers for custom endpoints."><title>Handlers in iroh_relay::server::http_server - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.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]--><rustdoc-topbar><h2><a href="#">Handlers</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">1.5.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Handlers</a></h2><h3><a href="#deref-methods-HashMap%3C(Method,+%26'static+str),+Box%3Cdyn+Fn(Request%3CIncoming%3E,+Builder)+-%3E+HyperResult%3CResponse%3CBytesBody%3E%3E+%2B+Send+%2B+Sync+%2B+'static%3E%3E">Methods from Deref<<wbr>Target=<wbr>Hash<wbr>Map<(<wbr>Method, &'static str), Box<dyn Fn(<wbr>Request<<wbr>Incoming>, Builder) -> Hyper<wbr>Result<<wbr>Response<<wbr>Bytes<wbr>Body>> + Send + Sync + 'static>>></a></h3><ul class="block deref-methods"><li><a href="#method.capacity" title="capacity">capacity</a></li><li><a href="#method.clear" title="clear">clear</a></li><li><a href="#method.contains_key" title="contains_key">contains_key</a></li><li><a href="#method.drain" title="drain">drain</a></li><li><a href="#method.entry" title="entry">entry</a></li><li><a href="#method.extract_if" title="extract_if">extract_if</a></li><li><a href="#method.get" title="get">get</a></li><li><a href="#method.get_disjoint_mut" title="get_disjoint_mut">get_disjoint_mut</a></li><li><a href="#method.get_disjoint_unchecked_mut" title="get_disjoint_unchecked_mut">get_disjoint_unchecked_mut</a></li><li><a href="#method.get_key_value" title="get_key_value">get_key_value</a></li><li><a href="#method.get_mut" title="get_mut">get_mut</a></li><li><a href="#method.hasher" title="hasher">hasher</a></li><li><a href="#method.insert" title="insert">insert</a></li><li><a href="#method.is_empty" title="is_empty">is_empty</a></li><li><a href="#method.iter" title="iter">iter</a></li><li><a href="#method.iter_mut" title="iter_mut">iter_mut</a></li><li><a href="#method.keys" title="keys">keys</a></li><li><a href="#method.len" title="len">len</a></li><li><a href="#method.remove" title="remove">remove</a></li><li><a href="#method.remove_entry" title="remove_entry">remove_entry</a></li><li><a href="#method.reserve" title="reserve">reserve</a></li><li><a href="#method.retain" title="retain">retain</a></li><li><a href="#method.shrink_to" title="shrink_to">shrink_to</a></li><li><a href="#method.shrink_to_fit" title="shrink_to_fit">shrink_to_fit</a></li><li><a href="#method.try_insert" title="try_insert">try_insert</a></li><li><a href="#method.try_reserve" title="try_reserve">try_reserve</a></li><li><a href="#method.values" title="values">values</a></li><li><a href="#method.values_mut" title="values_mut">values_mut</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Debug-for-Handlers" title="Debug">Debug</a></li><li><a href="#impl-Default-for-Handlers" title="Default">Default</a></li><li><a href="#impl-Deref-for-Handlers" title="Deref">Deref</a></li><li><a href="#impl-DerefMut-for-Handlers" title="DerefMut">DerefMut</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-Handlers" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-UnwindSafe-for-Handlers" title="!UnwindSafe">!UnwindSafe</a></li><li><a href="#impl-Freeze-for-Handlers" title="Freeze">Freeze</a></li><li><a href="#impl-Send-for-Handlers" title="Send">Send</a></li><li><a href="#impl-Sync-for-Handlers" title="Sync">Sync</a></li><li><a href="#impl-Unpin-for-Handlers" title="Unpin">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block blanket-implementation"><li><a href="#impl-Any-for-T" title="Any">Any</a></li><li><a href="#impl-AsTaggedExplicit%3C'a,+E%3E-for-T" title="AsTaggedExplicit<'a, E>">AsTaggedExplicit<'a, E></a></li><li><a href="#impl-AsTaggedImplicit%3C'a,+E%3E-for-T" title="AsTaggedImplicit<'a, E>">AsTaggedImplicit<'a, E></a></li><li><a href="#impl-Borrow%3CT%3E-for-T" title="Borrow<T>">Borrow<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut<T>">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-T" title="From<T>">From<T></a></li><li><a href="#impl-Instrument-for-T" title="Instrument">Instrument</a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into<U>">Into<U></a></li><li><a href="#impl-IntoEither-for-T" title="IntoEither">IntoEither</a></li><li><a href="#impl-PolicyExt-for-T" title="PolicyExt">PolicyExt</a></li><li><a href="#impl-Receiver-for-P" title="Receiver">Receiver</a></li><li><a href="#impl-Same-for-T" title="Same">Same</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom<U>">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto<U>">TryInto<U></a></li><li><a href="#impl-WithSubscriber-for-T" title="WithSubscriber">WithSubscriber</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>relay::<wbr>server::<wbr>http_<wbr>server</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">iroh_relay</a>::<wbr><a href="../index.html">server</a>::<wbr><a href="index.html">http_server</a></div><h1>Struct <span class="struct">Handlers</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/iroh_relay/server/http_server.rs.html#1164">Source</a> </span></div><pre class="rust item-decl"><code>pub struct Handlers(<span class="comment">/* private fields */</span>);</code></pre><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>server</code></strong> only.</div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A collection of HTTP request handlers for custom endpoints.</p>
|
||
</div></details><details class="toggle big-toggle" open><summary><h2 id="deref-methods-HashMap%3C(Method,+%26'static+str),+Box%3Cdyn+Fn(Request%3CIncoming%3E,+Builder)+-%3E+HyperResult%3CResponse%3CBytesBody%3E%3E+%2B+Send+%2B+Sync+%2B+'static%3E%3E" class="section-header"><span>Methods from <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><(Method, &'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>), <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Request<Incoming>, Builder) -> <a class="type" href="type.HyperResult.html" title="type iroh_relay::server::http_server::HyperResult">HyperResult</a><Response<<a class="type" href="type.BytesBody.html" title="type iroh_relay::server::http_server::BytesBody">BytesBody</a>>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static>>></span><a href="#deref-methods-HashMap%3C(Method,+%26'static+str),+Box%3Cdyn+Fn(Request%3CIncoming%3E,+Builder)+-%3E+HyperResult%3CResponse%3CBytesBody%3E%3E+%2B+Send+%2B+Sync+%2B+'static%3E%3E" class="anchor">§</a></h2></summary><div id="deref-methods-HashMap%3C(Method,+%26'static+str),+Box%3Cdyn+Fn(Request%3CIncoming%3E,+Builder)+-%3E+HyperResult%3CResponse%3CBytesBody%3E%3E+%2B+Send+%2B+Sync+%2B+'static%3E%3E-1" class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.capacity" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#365">Source</a></span><h4 class="code-header">pub fn <a href="#method.capacity" class="fn">capacity</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of elements the map can hold without reallocating.</p>
|
||
<p>This number is a lower bound; the <code>HashMap<K, V></code> might be able to hold
|
||
more, but is guaranteed to be able to hold at least this many.</p>
|
||
<h5 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
<span class="kw">let </span>map: HashMap<i32, i32> = HashMap::with_capacity(<span class="number">100</span>);
|
||
<span class="macro">assert!</span>(map.capacity() >= <span class="number">100</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.keys" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#394">Source</a></span><h4 class="code-header">pub fn <a href="#method.keys" class="fn">keys</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.Keys.html" title="struct std::collections::hash::map::Keys">Keys</a><'_, K, V></h4></section></summary><div class="docblock"><p>An iterator visiting all keys in arbitrary order.
|
||
The iterator element type is <code>&'a K</code>.</p>
|
||
<h5 id="examples-1"><a class="doc-anchor" href="#examples-1">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span>map = HashMap::from([
|
||
(<span class="string">"a"</span>, <span class="number">1</span>),
|
||
(<span class="string">"b"</span>, <span class="number">2</span>),
|
||
(<span class="string">"c"</span>, <span class="number">3</span>),
|
||
]);
|
||
|
||
<span class="kw">for </span>key <span class="kw">in </span>map.keys() {
|
||
<span class="macro">println!</span>(<span class="string">"{key}"</span>);
|
||
}</code></pre></div><h5 id="performance"><a class="doc-anchor" href="#performance">§</a>Performance</h5>
|
||
<p>In the current implementation, iterating over keys takes O(capacity) time
|
||
instead of O(len) because it internally visits empty buckets too.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.values" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#456">Source</a></span><h4 class="code-header">pub fn <a href="#method.values" class="fn">values</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.Values.html" title="struct std::collections::hash::map::Values">Values</a><'_, K, V></h4></section></summary><div class="docblock"><p>An iterator visiting all values in arbitrary order.
|
||
The iterator element type is <code>&'a V</code>.</p>
|
||
<h5 id="examples-2"><a class="doc-anchor" href="#examples-2">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span>map = HashMap::from([
|
||
(<span class="string">"a"</span>, <span class="number">1</span>),
|
||
(<span class="string">"b"</span>, <span class="number">2</span>),
|
||
(<span class="string">"c"</span>, <span class="number">3</span>),
|
||
]);
|
||
|
||
<span class="kw">for </span>val <span class="kw">in </span>map.values() {
|
||
<span class="macro">println!</span>(<span class="string">"{val}"</span>);
|
||
}</code></pre></div><h5 id="performance-1"><a class="doc-anchor" href="#performance-1">§</a>Performance</h5>
|
||
<p>In the current implementation, iterating over values takes O(capacity) time
|
||
instead of O(len) because it internally visits empty buckets too.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.values_mut" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.10.0">1.10.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#489">Source</a></span><h4 class="code-header">pub fn <a href="#method.values_mut" class="fn">values_mut</a>(&mut self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.ValuesMut.html" title="struct std::collections::hash::map::ValuesMut">ValuesMut</a><'_, K, V></h4></section></summary><div class="docblock"><p>An iterator visiting all values mutably in arbitrary order.
|
||
The iterator element type is <code>&'a mut V</code>.</p>
|
||
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::from([
|
||
(<span class="string">"a"</span>, <span class="number">1</span>),
|
||
(<span class="string">"b"</span>, <span class="number">2</span>),
|
||
(<span class="string">"c"</span>, <span class="number">3</span>),
|
||
]);
|
||
|
||
<span class="kw">for </span>val <span class="kw">in </span>map.values_mut() {
|
||
<span class="kw-2">*</span>val = <span class="kw-2">*</span>val + <span class="number">10</span>;
|
||
}
|
||
|
||
<span class="kw">for </span>val <span class="kw">in </span>map.values() {
|
||
<span class="macro">println!</span>(<span class="string">"{val}"</span>);
|
||
}</code></pre></div><h5 id="performance-2"><a class="doc-anchor" href="#performance-2">§</a>Performance</h5>
|
||
<p>In the current implementation, iterating over values takes O(capacity) time
|
||
instead of O(len) because it internally visits empty buckets too.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.iter" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#551">Source</a></span><h4 class="code-header">pub fn <a href="#method.iter" class="fn">iter</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.Iter.html" title="struct std::collections::hash::map::Iter">Iter</a><'_, K, V></h4></section></summary><div class="docblock"><p>An iterator visiting all key-value pairs in arbitrary order.
|
||
The iterator element type is <code>(&'a K, &'a V)</code>.</p>
|
||
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span>map = HashMap::from([
|
||
(<span class="string">"a"</span>, <span class="number">1</span>),
|
||
(<span class="string">"b"</span>, <span class="number">2</span>),
|
||
(<span class="string">"c"</span>, <span class="number">3</span>),
|
||
]);
|
||
|
||
<span class="kw">for </span>(key, val) <span class="kw">in </span>map.iter() {
|
||
<span class="macro">println!</span>(<span class="string">"key: {key} val: {val}"</span>);
|
||
}</code></pre></div><h5 id="performance-3"><a class="doc-anchor" href="#performance-3">§</a>Performance</h5>
|
||
<p>In the current implementation, iterating over map takes O(capacity) time
|
||
instead of O(len) because it internally visits empty buckets too.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.iter_mut" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#586">Source</a></span><h4 class="code-header">pub fn <a href="#method.iter_mut" class="fn">iter_mut</a>(&mut self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.IterMut.html" title="struct std::collections::hash::map::IterMut">IterMut</a><'_, K, V></h4></section></summary><div class="docblock"><p>An iterator visiting all key-value pairs in arbitrary order,
|
||
with mutable references to the values.
|
||
The iterator element type is <code>(&'a K, &'a mut V)</code>.</p>
|
||
<h5 id="examples-5"><a class="doc-anchor" href="#examples-5">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::from([
|
||
(<span class="string">"a"</span>, <span class="number">1</span>),
|
||
(<span class="string">"b"</span>, <span class="number">2</span>),
|
||
(<span class="string">"c"</span>, <span class="number">3</span>),
|
||
]);
|
||
|
||
<span class="comment">// Update all values
|
||
</span><span class="kw">for </span>(<span class="kw">_</span>, val) <span class="kw">in </span>map.iter_mut() {
|
||
<span class="kw-2">*</span>val <span class="kw-2">*</span>= <span class="number">2</span>;
|
||
}
|
||
|
||
<span class="kw">for </span>(key, val) <span class="kw">in </span><span class="kw-2">&</span>map {
|
||
<span class="macro">println!</span>(<span class="string">"key: {key} val: {val}"</span>);
|
||
}</code></pre></div><h5 id="performance-4"><a class="doc-anchor" href="#performance-4">§</a>Performance</h5>
|
||
<p>In the current implementation, iterating over map takes O(capacity) time
|
||
instead of O(len) because it internally visits empty buckets too.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.len" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#603">Source</a></span><h4 class="code-header">pub fn <a href="#method.len" class="fn">len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of elements in the map.</p>
|
||
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>a = HashMap::new();
|
||
<span class="macro">assert_eq!</span>(a.len(), <span class="number">0</span>);
|
||
a.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq!</span>(a.len(), <span class="number">1</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.is_empty" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#621">Source</a></span><h4 class="code-header">pub fn <a href="#method.is_empty" class="fn">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the map contains no elements.</p>
|
||
<h5 id="examples-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>a = HashMap::new();
|
||
<span class="macro">assert!</span>(a.is_empty());
|
||
a.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert!</span>(!a.is_empty());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.drain" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.6.0">1.6.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#651">Source</a></span><h4 class="code-header">pub fn <a href="#method.drain" class="fn">drain</a>(&mut self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.Drain.html" title="struct std::collections::hash::map::Drain">Drain</a><'_, K, V></h4></section></summary><div class="docblock"><p>Clears the map, returning all key-value pairs as an iterator. Keeps the
|
||
allocated memory for reuse.</p>
|
||
<p>If the returned iterator is dropped before being fully consumed, it
|
||
drops the remaining key-value pairs. The returned iterator keeps a
|
||
mutable borrow on the map to optimize its implementation.</p>
|
||
<h5 id="examples-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>a = HashMap::new();
|
||
a.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
a.insert(<span class="number">2</span>, <span class="string">"b"</span>);
|
||
|
||
<span class="kw">for </span>(k, v) <span class="kw">in </span>a.drain().take(<span class="number">1</span>) {
|
||
<span class="macro">assert!</span>(k == <span class="number">1 </span>|| k == <span class="number">2</span>);
|
||
<span class="macro">assert!</span>(v == <span class="string">"a" </span>|| v == <span class="string">"b"</span>);
|
||
}
|
||
|
||
<span class="macro">assert!</span>(a.is_empty());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.extract_if" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.88.0">1.88.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#691-693">Source</a></span><h4 class="code-header">pub fn <a href="#method.extract_if" class="fn">extract_if</a><F>(&mut self, pred: F) -> <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.ExtractIf.html" title="struct std::collections::hash::map::ExtractIf">ExtractIf</a><'_, K, V, F><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&K</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut V</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Creates an iterator which uses a closure to determine if an element (key-value pair) should be removed.</p>
|
||
<p>If the closure returns <code>true</code>, the element is removed from the map and
|
||
yielded. If the closure returns <code>false</code>, or panics, the element remains
|
||
in the map and will not be yielded.</p>
|
||
<p>The iterator also lets you mutate the value of each element in the
|
||
closure, regardless of whether you choose to keep or remove it.</p>
|
||
<p>If the returned <code>ExtractIf</code> is not exhausted, e.g. because it is dropped without iterating
|
||
or the iteration short-circuits, then the remaining elements will be retained.
|
||
Use <a href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html#method.retain" title="method std::collections::hash::map::HashMap::retain"><code>retain</code></a> with a negated predicate if you do not need the returned iterator.</p>
|
||
<h5 id="examples-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</h5>
|
||
<p>Splitting a map into even and odd keys, reusing the original map:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map: HashMap<i32, i32> = (<span class="number">0</span>..<span class="number">8</span>).map(|x| (x, x)).collect();
|
||
<span class="kw">let </span>extracted: HashMap<i32, i32> = map.extract_if(|k, _v| k % <span class="number">2 </span>== <span class="number">0</span>).collect();
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>evens = extracted.keys().copied().collect::<Vec<<span class="kw">_</span>>>();
|
||
<span class="kw">let </span><span class="kw-2">mut </span>odds = map.keys().copied().collect::<Vec<<span class="kw">_</span>>>();
|
||
evens.sort();
|
||
odds.sort();
|
||
|
||
<span class="macro">assert_eq!</span>(evens, <span class="macro">vec!</span>[<span class="number">0</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">6</span>]);
|
||
<span class="macro">assert_eq!</span>(odds, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>]);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.retain" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.18.0">1.18.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#720-722">Source</a></span><h4 class="code-header">pub fn <a href="#method.retain" class="fn">retain</a><F>(&mut self, f: F)<div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&K</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut V</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class="docblock"><p>Retains only the elements specified by the predicate.</p>
|
||
<p>In other words, remove all pairs <code>(k, v)</code> for which <code>f(&k, &mut v)</code> returns <code>false</code>.
|
||
The elements are visited in unsorted (and unspecified) order.</p>
|
||
<h5 id="examples-10"><a class="doc-anchor" href="#examples-10">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map: HashMap<i32, i32> = (<span class="number">0</span>..<span class="number">8</span>).map(|x| (x, x<span class="kw-2">*</span><span class="number">10</span>)).collect();
|
||
map.retain(|<span class="kw-2">&</span>k, <span class="kw">_</span>| k % <span class="number">2 </span>== <span class="number">0</span>);
|
||
<span class="macro">assert_eq!</span>(map.len(), <span class="number">4</span>);</code></pre></div><h5 id="performance-5"><a class="doc-anchor" href="#performance-5">§</a>Performance</h5>
|
||
<p>In the current implementation, this operation takes O(capacity) time
|
||
instead of O(len) because it internally visits empty buckets too.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.clear" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#742">Source</a></span><h4 class="code-header">pub fn <a href="#method.clear" class="fn">clear</a>(&mut self)</h4></section></summary><div class="docblock"><p>Clears the map, removing all key-value pairs. Keeps the allocated memory
|
||
for reuse.</p>
|
||
<h5 id="examples-11"><a class="doc-anchor" href="#examples-11">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>a = HashMap::new();
|
||
a.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
a.clear();
|
||
<span class="macro">assert!</span>(a.is_empty());</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.hasher" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.9.0">1.9.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#760">Source</a></span><h4 class="code-header">pub fn <a href="#method.hasher" class="fn">hasher</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&S</a></h4></section></summary><div class="docblock"><p>Returns a reference to the map’s <a href="https://doc.rust-lang.org/nightly/core/hash/trait.BuildHasher.html" title="trait core::hash::BuildHasher"><code>BuildHasher</code></a>.</p>
|
||
<h5 id="examples-12"><a class="doc-anchor" href="#examples-12">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
<span class="kw">use </span>std::hash::RandomState;
|
||
|
||
<span class="kw">let </span>hasher = RandomState::new();
|
||
<span class="kw">let </span>map: HashMap<i32, i32> = HashMap::with_hasher(hasher);
|
||
<span class="kw">let </span>hasher: <span class="kw-2">&</span>RandomState = map.hasher();</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.reserve" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#789">Source</a></span><h4 class="code-header">pub fn <a href="#method.reserve" class="fn">reserve</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Reserves capacity for at least <code>additional</code> more elements to be inserted
|
||
in the <code>HashMap</code>. The collection may reserve more space to speculatively
|
||
avoid frequent reallocations. After calling <code>reserve</code>,
|
||
capacity will be greater than or equal to <code>self.len() + additional</code>.
|
||
Does nothing if capacity is already sufficient.</p>
|
||
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
|
||
<p>Panics if the new allocation size overflows <a href="https://doc.rust-lang.org/nightly/std/primitive.usize.html" title="primitive usize"><code>usize</code></a>.</p>
|
||
<h5 id="examples-13"><a class="doc-anchor" href="#examples-13">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map: HashMap<<span class="kw-2">&</span>str, i32> = HashMap::new();
|
||
map.reserve(<span class="number">10</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.try_reserve" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.57.0">1.57.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#815">Source</a></span><h4 class="code-header">pub fn <a href="#method.try_reserve" class="fn">try_reserve</a>(&mut self, additional: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/collections/struct.TryReserveError.html" title="struct alloc::collections::TryReserveError">TryReserveError</a>></h4></section></summary><div class="docblock"><p>Tries to reserve capacity for at least <code>additional</code> more elements to be inserted
|
||
in the <code>HashMap</code>. The collection may reserve more space to speculatively
|
||
avoid frequent reallocations. After calling <code>try_reserve</code>,
|
||
capacity will be greater than or equal to <code>self.len() + additional</code> if
|
||
it returns <code>Ok(())</code>.
|
||
Does nothing if capacity is already sufficient.</p>
|
||
<h5 id="errors"><a class="doc-anchor" href="#errors">§</a>Errors</h5>
|
||
<p>If the capacity overflows, or the allocator reports a failure, then an error
|
||
is returned.</p>
|
||
<h5 id="examples-14"><a class="doc-anchor" href="#examples-14">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map: HashMap<<span class="kw-2">&</span>str, isize> = HashMap::new();
|
||
map.try_reserve(<span class="number">10</span>).expect(<span class="string">"why is the test harness OOMing on a handful of bytes?"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.shrink_to_fit" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#837">Source</a></span><h4 class="code-header">pub fn <a href="#method.shrink_to_fit" class="fn">shrink_to_fit</a>(&mut self)</h4></section></summary><div class="docblock"><p>Shrinks the capacity of the map as much as possible. It will drop
|
||
down as much as possible while maintaining the internal rules
|
||
and possibly leaving some space in accordance with the resize policy.</p>
|
||
<h5 id="examples-15"><a class="doc-anchor" href="#examples-15">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map: HashMap<i32, i32> = HashMap::with_capacity(<span class="number">100</span>);
|
||
map.insert(<span class="number">1</span>, <span class="number">2</span>);
|
||
map.insert(<span class="number">3</span>, <span class="number">4</span>);
|
||
<span class="macro">assert!</span>(map.capacity() >= <span class="number">100</span>);
|
||
map.shrink_to_fit();
|
||
<span class="macro">assert!</span>(map.capacity() >= <span class="number">2</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.shrink_to" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.56.0">1.56.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#863">Source</a></span><h4 class="code-header">pub fn <a href="#method.shrink_to" class="fn">shrink_to</a>(&mut self, min_capacity: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Shrinks the capacity of the map with a lower limit. It will drop
|
||
down no lower than the supplied limit while maintaining the internal rules
|
||
and possibly leaving some space in accordance with the resize policy.</p>
|
||
<p>If the current capacity is less than the lower limit, this is a no-op.</p>
|
||
<h5 id="examples-16"><a class="doc-anchor" href="#examples-16">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map: HashMap<i32, i32> = HashMap::with_capacity(<span class="number">100</span>);
|
||
map.insert(<span class="number">1</span>, <span class="number">2</span>);
|
||
map.insert(<span class="number">3</span>, <span class="number">4</span>);
|
||
<span class="macro">assert!</span>(map.capacity() >= <span class="number">100</span>);
|
||
map.shrink_to(<span class="number">10</span>);
|
||
<span class="macro">assert!</span>(map.capacity() >= <span class="number">10</span>);
|
||
map.shrink_to(<span class="number">0</span>);
|
||
<span class="macro">assert!</span>(map.capacity() >= <span class="number">2</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.entry" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#887">Source</a></span><h4 class="code-header">pub fn <a href="#method.entry" class="fn">entry</a>(&mut self, key: K) -> <a class="enum" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/enum.Entry.html" title="enum std::collections::hash::map::Entry">Entry</a><'_, K, V></h4></section></summary><div class="docblock"><p>Gets the given key’s corresponding entry in the map for in-place manipulation.</p>
|
||
<h5 id="examples-17"><a class="doc-anchor" href="#examples-17">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>letters = HashMap::new();
|
||
|
||
<span class="kw">for </span>ch <span class="kw">in </span><span class="string">"a short treatise on fungi"</span>.chars() {
|
||
letters.entry(ch).and_modify(|counter| <span class="kw-2">*</span>counter += <span class="number">1</span>).or_insert(<span class="number">1</span>);
|
||
}
|
||
|
||
<span class="macro">assert_eq!</span>(letters[<span class="kw-2">&</span><span class="string">'s'</span>], <span class="number">2</span>);
|
||
<span class="macro">assert_eq!</span>(letters[<span class="kw-2">&</span><span class="string">'t'</span>], <span class="number">3</span>);
|
||
<span class="macro">assert_eq!</span>(letters[<span class="kw-2">&</span><span class="string">'u'</span>], <span class="number">1</span>);
|
||
<span class="macro">assert_eq!</span>(letters.get(<span class="kw-2">&</span><span class="string">'y'</span>), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.get" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#909-912">Source</a></span><h4 class="code-header">pub fn <a href="#method.get" class="fn">get</a><Q>(&self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&V</a>><div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns a reference to the value corresponding to the key.</p>
|
||
<p>The key may be any borrowed form of the map’s key type, but
|
||
<a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h5 id="examples-18"><a class="doc-anchor" href="#examples-18">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
map.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq!</span>(map.get(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="kw-2">&</span><span class="string">"a"</span>));
|
||
<span class="macro">assert_eq!</span>(map.get(<span class="kw-2">&</span><span class="number">2</span>), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.get_key_value" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.40.0">1.40.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#967-970">Source</a></span><h4 class="code-header">pub fn <a href="#method.get_key_value" class="fn">get_key_value</a><Q>(&self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&K</a>, <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&V</a>)><div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns the key-value pair corresponding to the supplied key. This is
|
||
potentially useful:</p>
|
||
<ul>
|
||
<li>for key types where non-identical keys can be considered equal;</li>
|
||
<li>for getting the <code>&K</code> stored key value from a borrowed <code>&Q</code> lookup key; or</li>
|
||
<li>for getting a reference to a key with the same lifetime as the collection.</li>
|
||
</ul>
|
||
<p>The supplied key may be any borrowed form of the map’s key type, but
|
||
<a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h5 id="examples-19"><a class="doc-anchor" href="#examples-19">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
<span class="kw">use </span>std::hash::{Hash, Hasher};
|
||
|
||
<span class="attr">#[derive(Clone, Copy, Debug)]
|
||
</span><span class="kw">struct </span>S {
|
||
id: u32,
|
||
name: <span class="kw-2">&</span><span class="lifetime">'static </span>str, <span class="comment">// ignored by equality and hashing operations
|
||
</span>}
|
||
|
||
<span class="kw">impl </span>PartialEq <span class="kw">for </span>S {
|
||
<span class="kw">fn </span>eq(<span class="kw-2">&</span><span class="self">self</span>, other: <span class="kw-2">&</span>S) -> bool {
|
||
<span class="self">self</span>.id == other.id
|
||
}
|
||
}
|
||
|
||
<span class="kw">impl </span>Eq <span class="kw">for </span>S {}
|
||
|
||
<span class="kw">impl </span>Hash <span class="kw">for </span>S {
|
||
<span class="kw">fn </span>hash<H: Hasher>(<span class="kw-2">&</span><span class="self">self</span>, state: <span class="kw-2">&mut </span>H) {
|
||
<span class="self">self</span>.id.hash(state);
|
||
}
|
||
}
|
||
|
||
<span class="kw">let </span>j_a = S { id: <span class="number">1</span>, name: <span class="string">"Jessica" </span>};
|
||
<span class="kw">let </span>j_b = S { id: <span class="number">1</span>, name: <span class="string">"Jess" </span>};
|
||
<span class="kw">let </span>p = S { id: <span class="number">2</span>, name: <span class="string">"Paul" </span>};
|
||
<span class="macro">assert_eq!</span>(j_a, j_b);
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
map.insert(j_a, <span class="string">"Paris"</span>);
|
||
<span class="macro">assert_eq!</span>(map.get_key_value(<span class="kw-2">&</span>j_a), <span class="prelude-val">Some</span>((<span class="kw-2">&</span>j_a, <span class="kw-2">&</span><span class="string">"Paris"</span>)));
|
||
<span class="macro">assert_eq!</span>(map.get_key_value(<span class="kw-2">&</span>j_b), <span class="prelude-val">Some</span>((<span class="kw-2">&</span>j_a, <span class="kw-2">&</span><span class="string">"Paris"</span>))); <span class="comment">// the notable case
|
||
</span><span class="macro">assert_eq!</span>(map.get_key_value(<span class="kw-2">&</span>p), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.get_disjoint_mut" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.86.0">1.86.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1046-1052">Source</a></span><h4 class="code-header">pub fn <a href="#method.get_disjoint_mut" class="fn">get_disjoint_mut</a><Q, const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>(
|
||
&mut self,
|
||
ks: [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">N</a>],
|
||
) -> [<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut V</a>>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">N</a>]<div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Attempts to get mutable references to <code>N</code> values in the map at once.</p>
|
||
<p>Returns an array of length <code>N</code> with the results of each query. For soundness, at most one
|
||
mutable reference will be returned to any value. <code>None</code> will be used if the key is missing.</p>
|
||
<p>This method performs a check to ensure there are no duplicate keys, which currently has a time-complexity of O(n^2),
|
||
so be careful when passing many keys.</p>
|
||
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
|
||
<p>Panics if any keys are overlapping.</p>
|
||
<h5 id="examples-20"><a class="doc-anchor" href="#examples-20">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>libraries = HashMap::new();
|
||
libraries.insert(<span class="string">"Bodleian Library"</span>.to_string(), <span class="number">1602</span>);
|
||
libraries.insert(<span class="string">"Athenæum"</span>.to_string(), <span class="number">1807</span>);
|
||
libraries.insert(<span class="string">"Herzogin-Anna-Amalia-Bibliothek"</span>.to_string(), <span class="number">1691</span>);
|
||
libraries.insert(<span class="string">"Library of Congress"</span>.to_string(), <span class="number">1800</span>);
|
||
|
||
<span class="comment">// Get Athenæum and Bodleian Library
|
||
</span><span class="kw">let </span>[<span class="prelude-val">Some</span>(a), <span class="prelude-val">Some</span>(b)] = libraries.get_disjoint_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"Bodleian Library"</span>,
|
||
]) <span class="kw">else </span>{ <span class="macro">panic!</span>() };
|
||
|
||
<span class="comment">// Assert values of Athenæum and Library of Congress
|
||
</span><span class="kw">let </span>got = libraries.get_disjoint_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"Library of Congress"</span>,
|
||
]);
|
||
<span class="macro">assert_eq!</span>(
|
||
got,
|
||
[
|
||
<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="number">1807</span>),
|
||
<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="number">1800</span>),
|
||
],
|
||
);
|
||
|
||
<span class="comment">// Missing keys result in None
|
||
</span><span class="kw">let </span>got = libraries.get_disjoint_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"New York Public Library"</span>,
|
||
]);
|
||
<span class="macro">assert_eq!</span>(
|
||
got,
|
||
[
|
||
<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="number">1807</span>),
|
||
<span class="prelude-val">None
|
||
</span>]
|
||
);</code></pre></div>
|
||
<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">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>libraries = HashMap::new();
|
||
libraries.insert(<span class="string">"Athenæum"</span>.to_string(), <span class="number">1807</span>);
|
||
|
||
<span class="comment">// Duplicate keys panic!
|
||
</span><span class="kw">let </span>got = libraries.get_disjoint_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"Athenæum"</span>,
|
||
]);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.get_disjoint_unchecked_mut" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.86.0">1.86.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1113-1119">Source</a></span><h4 class="code-header">pub unsafe fn <a href="#method.get_disjoint_unchecked_mut" class="fn">get_disjoint_unchecked_mut</a><Q, const N: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>>(
|
||
&mut self,
|
||
ks: [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">N</a>],
|
||
) -> [<a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut V</a>>; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.array.html">N</a>]<div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Attempts to get mutable references to <code>N</code> values in the map at once, without validating that
|
||
the values are unique.</p>
|
||
<p>Returns an array of length <code>N</code> with the results of each query. <code>None</code> will be used if
|
||
the key is missing.</p>
|
||
<p>For a safe alternative see <a href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html#method.get_disjoint_mut" title="method std::collections::hash::map::HashMap::get_disjoint_mut"><code>get_disjoint_mut</code></a>.</p>
|
||
<h5 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h5>
|
||
<p>Calling this method with overlapping keys is <em><a href="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">undefined behavior</a></em> even if the resulting
|
||
references are not used.</p>
|
||
<h5 id="examples-21"><a class="doc-anchor" href="#examples-21">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>libraries = HashMap::new();
|
||
libraries.insert(<span class="string">"Bodleian Library"</span>.to_string(), <span class="number">1602</span>);
|
||
libraries.insert(<span class="string">"Athenæum"</span>.to_string(), <span class="number">1807</span>);
|
||
libraries.insert(<span class="string">"Herzogin-Anna-Amalia-Bibliothek"</span>.to_string(), <span class="number">1691</span>);
|
||
libraries.insert(<span class="string">"Library of Congress"</span>.to_string(), <span class="number">1800</span>);
|
||
|
||
<span class="comment">// SAFETY: The keys do not overlap.
|
||
</span><span class="kw">let </span>[<span class="prelude-val">Some</span>(a), <span class="prelude-val">Some</span>(b)] = (<span class="kw">unsafe </span>{ libraries.get_disjoint_unchecked_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"Bodleian Library"</span>,
|
||
]) }) <span class="kw">else </span>{ <span class="macro">panic!</span>() };
|
||
|
||
<span class="comment">// SAFETY: The keys do not overlap.
|
||
</span><span class="kw">let </span>got = <span class="kw">unsafe </span>{ libraries.get_disjoint_unchecked_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"Library of Congress"</span>,
|
||
]) };
|
||
<span class="macro">assert_eq!</span>(
|
||
got,
|
||
[
|
||
<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="number">1807</span>),
|
||
<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="number">1800</span>),
|
||
],
|
||
);
|
||
|
||
<span class="comment">// SAFETY: The keys do not overlap.
|
||
</span><span class="kw">let </span>got = <span class="kw">unsafe </span>{ libraries.get_disjoint_unchecked_mut([
|
||
<span class="string">"Athenæum"</span>,
|
||
<span class="string">"New York Public Library"</span>,
|
||
]) };
|
||
<span class="comment">// Missing keys result in None
|
||
</span><span class="macro">assert_eq!</span>(got, [<span class="prelude-val">Some</span>(<span class="kw-2">&mut </span><span class="number">1807</span>), <span class="prelude-val">None</span>]);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.contains_key" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1143-1146">Source</a></span><h4 class="code-header">pub fn <a href="#method.contains_key" class="fn">contains_key</a><Q>(&self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a><div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the map contains a value for the specified key.</p>
|
||
<p>The key may be any borrowed form of the map’s key type, but
|
||
<a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h5 id="examples-22"><a class="doc-anchor" href="#examples-22">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
map.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq!</span>(map.contains_key(<span class="kw-2">&</span><span class="number">1</span>), <span class="bool-val">true</span>);
|
||
<span class="macro">assert_eq!</span>(map.contains_key(<span class="kw-2">&</span><span class="number">2</span>), <span class="bool-val">false</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.get_mut" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1171-1174">Source</a></span><h4 class="code-header">pub fn <a href="#method.get_mut" class="fn">get_mut</a><Q>(&mut self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut V</a>><div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Returns a mutable reference to the value corresponding to the key.</p>
|
||
<p>The key may be any borrowed form of the map’s key type, but
|
||
<a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h5 id="examples-23"><a class="doc-anchor" href="#examples-23">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
map.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="kw">if let </span><span class="prelude-val">Some</span>(x) = map.get_mut(<span class="kw-2">&</span><span class="number">1</span>) {
|
||
<span class="kw-2">*</span>x = <span class="string">"b"</span>;
|
||
}
|
||
<span class="macro">assert_eq!</span>(map[<span class="kw-2">&</span><span class="number">1</span>], <span class="string">"b"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.insert" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1207">Source</a></span><h4 class="code-header">pub fn <a href="#method.insert" class="fn">insert</a>(&mut self, k: K, v: V) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><V></h4></section></summary><div class="docblock"><p>Inserts a key-value pair into the map.</p>
|
||
<p>If the map did not have this key present, <a href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None" title="variant core::option::Option::None"><code>None</code></a> is returned.</p>
|
||
<p>If the map did have this key present, the value is updated, and the old
|
||
value is returned. The key is not updated, though; this matters for
|
||
types that can be <code>==</code> without being identical. See the <a href="https://doc.rust-lang.org/nightly/std/collections/index.html#insert-and-complex-keys" title="mod std::collections">module-level
|
||
documentation</a> for more.</p>
|
||
<h5 id="examples-24"><a class="doc-anchor" href="#examples-24">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
<span class="macro">assert_eq!</span>(map.insert(<span class="number">37</span>, <span class="string">"a"</span>), <span class="prelude-val">None</span>);
|
||
<span class="macro">assert_eq!</span>(map.is_empty(), <span class="bool-val">false</span>);
|
||
|
||
map.insert(<span class="number">37</span>, <span class="string">"b"</span>);
|
||
<span class="macro">assert_eq!</span>(map.insert(<span class="number">37</span>, <span class="string">"c"</span>), <span class="prelude-val">Some</span>(<span class="string">"b"</span>));
|
||
<span class="macro">assert_eq!</span>(map[<span class="kw-2">&</span><span class="number">37</span>], <span class="string">"c"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.try_insert" class="method"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1235">Source</a><h4 class="code-header">pub fn <a href="#method.try_insert" class="fn">try_insert</a>(
|
||
&mut self,
|
||
key: K,
|
||
value: V,
|
||
) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut V</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.OccupiedError.html" title="struct std::collections::hash::map::OccupiedError">OccupiedError</a><'_, K, V>></h4></section><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>map_try_insert</code>)</span></div></span></summary><div class="docblock"><p>Tries to insert a key-value pair into the map, and returns
|
||
a mutable reference to the value in the entry.</p>
|
||
<p>If the map already had this key present, nothing is updated, and
|
||
an error containing the occupied entry and the value is returned.</p>
|
||
<h5 id="examples-25"><a class="doc-anchor" href="#examples-25">§</a>Examples</h5>
|
||
<p>Basic usage:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="attr">#![feature(map_try_insert)]
|
||
|
||
</span><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
<span class="macro">assert_eq!</span>(map.try_insert(<span class="number">37</span>, <span class="string">"a"</span>).unwrap(), <span class="kw-2">&</span><span class="string">"a"</span>);
|
||
|
||
<span class="kw">let </span>err = map.try_insert(<span class="number">37</span>, <span class="string">"b"</span>).unwrap_err();
|
||
<span class="macro">assert_eq!</span>(err.entry.key(), <span class="kw-2">&</span><span class="number">37</span>);
|
||
<span class="macro">assert_eq!</span>(err.entry.get(), <span class="kw-2">&</span><span class="string">"a"</span>);
|
||
<span class="macro">assert_eq!</span>(err.value, <span class="string">"b"</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.remove" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.0.0">1.0.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1262-1265">Source</a></span><h4 class="code-header">pub fn <a href="#method.remove" class="fn">remove</a><Q>(&mut self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><V><div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Removes a key from the map, returning the value at the key if the key
|
||
was previously in the map.</p>
|
||
<p>The key may be any borrowed form of the map’s key type, but
|
||
<a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h5 id="examples-26"><a class="doc-anchor" href="#examples-26">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
map.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq!</span>(map.remove(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>(<span class="string">"a"</span>));
|
||
<span class="macro">assert_eq!</span>(map.remove(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">None</span>);</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.remove_entry" class="method"><span class="rightside"><span class="since" title="Stable since Rust version 1.27.0">1.27.0</span> · <a class="src" href="https://doc.rust-lang.org/nightly/src/std/collections/hash/map.rs.html#1291-1294">Source</a></span><h4 class="code-header">pub fn <a href="#method.remove_entry" class="fn">remove_entry</a><Q>(&mut self, k: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&Q</a>) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a><<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.tuple.html">(K, V)</a>><div class="where">where
|
||
K: <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><Q>,
|
||
Q: <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h4></section></summary><div class="docblock"><p>Removes a key from the map, returning the stored key and value if the
|
||
key was previously in the map.</p>
|
||
<p>The key may be any borrowed form of the map’s key type, but
|
||
<a href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash"><code>Hash</code></a> and <a href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq"><code>Eq</code></a> on the borrowed form <em>must</em> match those for
|
||
the key type.</p>
|
||
<h5 id="examples-27"><a class="doc-anchor" href="#examples-27">§</a>Examples</h5>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::collections::HashMap;
|
||
|
||
<span class="kw">let </span><span class="kw-2">mut </span>map = HashMap::new();
|
||
map.insert(<span class="number">1</span>, <span class="string">"a"</span>);
|
||
<span class="macro">assert_eq!</span>(map.remove_entry(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">Some</span>((<span class="number">1</span>, <span class="string">"a"</span>)));
|
||
<span class="macro">assert_eq!</span>(map.remove(<span class="kw-2">&</span><span class="number">1</span>), <span class="prelude-val">None</span>);</code></pre></div></div></details></div></details><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-Debug-for-Handlers" class="impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1166-1174">Source</a><a href="#impl-Debug-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></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/iroh_relay/server/http_server.rs.html#1167-1173">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&self, f: &mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a><'_>) -> <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Default-for-Handlers" class="impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1163">Source</a><a href="#impl-Default-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></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/iroh_relay/server/http_server.rs.html#1163">Source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -> <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Deref-for-Handlers" class="impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1176-1182">Source</a><a href="#impl-Deref-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Target" class="associatedtype trait-impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1177">Source</a><a href="#associatedtype.Target" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#associatedtype.Target" class="associatedtype">Target</a> = <a class="struct" href="https://doc.rust-lang.org/nightly/std/collections/hash/map/struct.HashMap.html" title="struct std::collections::hash::map::HashMap">HashMap</a><(Method, &'static <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>), <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(Request<Incoming>, Builder) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><Response<<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn Body<Data = Bytes, Error = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>>>, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="https://doc.rust-lang.org/nightly/core/error/trait.Error.html" title="trait core::error::Error">Error</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>>> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>>></h4></section></summary><div class='docblock'>The resulting type after dereferencing.</div></details><details class="toggle method-toggle" open><summary><section id="method.deref" class="method trait-impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1179-1181">Source</a><a href="#method.deref" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#tymethod.deref" class="fn">deref</a>(&self) -> &Self::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#associatedtype.Target" title="type core::ops::deref::Deref::Target">Target</a></h4></section></summary><div class='docblock'>Dereferences the value.</div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-DerefMut-for-Handlers" class="impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1184-1188">Source</a><a href="#impl-DerefMut-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.deref_mut" class="method trait-impl"><a class="src rightside" href="../../../src/iroh_relay/server/http_server.rs.html#1185-1187">Source</a><a href="#method.deref_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.DerefMut.html#tymethod.deref_mut" class="fn">deref_mut</a>(&mut self) -> &mut Self::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html#associatedtype.Target" title="type core::ops::deref::Deref::Target">Target</a></h4></section></summary><div class='docblock'>Mutably dereferences the value.</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-Freeze-for-Handlers" class="impl"><a href="#impl-Freeze-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section><section id="impl-RefUnwindSafe-for-Handlers" class="impl"><a href="#impl-RefUnwindSafe-for-Handlers" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section><section id="impl-Send-for-Handlers" class="impl"><a href="#impl-Send-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section><section id="impl-Sync-for-Handlers" class="impl"><a href="#impl-Sync-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section><section id="impl-Unpin-for-Handlers" class="impl"><a href="#impl-Unpin-for-Handlers" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></h3></section><section id="impl-UnwindSafe-for-Handlers" class="impl"><a href="#impl-UnwindSafe-for-Handlers" class="anchor">§</a><h3 class="code-header">impl !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Handlers.html" title="struct iroh_relay::server::http_server::Handlers">Handlers</a></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/nightly/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
|
||
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/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/nightly/src/core/any.rs.html#139">Source</a><a href="#method.type_id" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&self) -> <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-AsTaggedExplicit%3C'a,+E%3E-for-T" class="impl"><a href="#impl-AsTaggedExplicit%3C'a,+E%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<'a, T, E> AsTaggedExplicit<'a, E> for T<div class="where">where
|
||
T: 'a,</div></h3></section></summary><div class="impl-items"><section id="method.explicit" class="method trait-impl"><a href="#method.explicit" class="anchor">§</a><h4 class="code-header">fn <a class="fn">explicit</a>(self, class: Class, tag: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> TaggedParser<'a, Explicit, Self, E></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-AsTaggedImplicit%3C'a,+E%3E-for-T" class="impl"><a href="#impl-AsTaggedImplicit%3C'a,+E%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<'a, T, E> AsTaggedImplicit<'a, E> for T<div class="where">where
|
||
T: 'a,</div></h3></section></summary><div class="impl-items"><section id="method.implicit" class="method trait-impl"><a href="#method.implicit" class="anchor">§</a><h4 class="code-header">fn <a class="fn">implicit</a>(
|
||
self,
|
||
class: Class,
|
||
constructed: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,
|
||
tag: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>,
|
||
) -> TaggedParser<'a, Implicit, Self, E></h4></section></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/nightly/src/core/borrow.rs.html#212">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/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/nightly/src/core/borrow.rs.html#214">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/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/nightly/src/core/borrow.rs.html#221">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a><T> for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/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/nightly/src/core/borrow.rs.html#222">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&mut self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></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/nightly/src/core/convert/mod.rs.html#785">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for T</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/nightly/src/core/convert/mod.rs.html#788">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -> 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-Instrument-for-T" class="impl"><a href="#impl-Instrument-for-T" class="anchor">§</a><h3 class="code-header">impl<T> Instrument for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.instrument" class="method trait-impl"><a href="#method.instrument" class="anchor">§</a><h4 class="code-header">fn <a class="fn">instrument</a>(self, span: Span) -> Instrumented<Self></h4></section></summary><div class='docblock'>Instruments this type with the provided [<code>Span</code>], returning an
|
||
<code>Instrumented</code> wrapper. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.in_current_span" class="method trait-impl"><a href="#method.in_current_span" class="anchor">§</a><h4 class="code-header">fn <a class="fn">in_current_span</a>(self) -> Instrumented<Self></h4></section></summary><div class='docblock'>Instruments this type with the <a href="super::Span::current()">current</a> <a href="crate::Span"><code>Span</code></a>, returning an
|
||
<code>Instrumented</code> wrapper. <a>Read more</a></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/nightly/src/core/convert/mod.rs.html#767-769">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T>,</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/nightly/src/core/convert/mod.rs.html#777">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -> 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/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a><T> for U</code> chooses to do.</p>
|
||
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-IntoEither-for-T" class="impl"><a class="src rightside" href="https://docs.rs/either/1/src/either/into_either.rs.html#64">Source</a><a href="#impl-IntoEither-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://docs.rs/either/1/either/into_either/trait.IntoEither.html" title="trait either::into_either::IntoEither">IntoEither</a> for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into_either" class="method trait-impl"><a class="src rightside" href="https://docs.rs/either/1/src/either/into_either.rs.html#29">Source</a><a href="#method.into_either" class="anchor">§</a><h4 class="code-header">fn <a href="https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either" class="fn">into_either</a>(self, into_left: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>) -> <a class="enum" href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either">Either</a><Self, Self></h4></section></summary><div class='docblock'>Converts <code>self</code> into a <a href="https://docs.rs/either/1/either/enum.Either.html#variant.Left" title="variant either::Either::Left"><code>Left</code></a> variant of <a href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
if <code>into_left</code> is <code>true</code>.
|
||
Converts <code>self</code> into a <a href="https://docs.rs/either/1/either/enum.Either.html#variant.Right" title="variant either::Either::Right"><code>Right</code></a> variant of <a href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
otherwise. <a href="https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.into_either_with" class="method trait-impl"><a class="src rightside" href="https://docs.rs/either/1/src/either/into_either.rs.html#55-57">Source</a><a href="#method.into_either_with" class="anchor">§</a><h4 class="code-header">fn <a href="https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either_with" class="fn">into_either_with</a><F>(self, into_left: F) -> <a class="enum" href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either">Either</a><Self, Self><div class="where">where
|
||
F: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnOnce.html" title="trait core::ops::function::FnOnce">FnOnce</a>(&Self) -> <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.bool.html">bool</a>,</div></h4></section></summary><div class='docblock'>Converts <code>self</code> into a <a href="https://docs.rs/either/1/either/enum.Either.html#variant.Left" title="variant either::Either::Left"><code>Left</code></a> variant of <a href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
if <code>into_left(&self)</code> returns <code>true</code>.
|
||
Converts <code>self</code> into a <a href="https://docs.rs/either/1/either/enum.Either.html#variant.Right" title="variant either::Either::Right"><code>Right</code></a> variant of <a href="https://docs.rs/either/1/either/enum.Either.html" title="enum either::Either"><code>Either<Self, Self></code></a>
|
||
otherwise. <a href="https://docs.rs/either/1/either/into_either/trait.IntoEither.html#method.into_either_with">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-PolicyExt-for-T" class="impl"><a href="#impl-PolicyExt-for-T" class="anchor">§</a><h3 class="code-header">impl<T> PolicyExt for T<div class="where">where
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/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.and" class="method trait-impl"><a href="#method.and" class="anchor">§</a><h4 class="code-header">fn <a class="fn">and</a><P, B, E>(self, other: P) -> And<T, P><div class="where">where
|
||
T: Policy<B, E>,
|
||
P: Policy<B, E>,</div></h4></section></summary><div class='docblock'>Create a new <code>Policy</code> that returns [<code>Action::Follow</code>] only if <code>self</code> and <code>other</code> return
|
||
<code>Action::Follow</code>. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.or" class="method trait-impl"><a href="#method.or" class="anchor">§</a><h4 class="code-header">fn <a class="fn">or</a><P, B, E>(self, other: P) -> Or<T, P><div class="where">where
|
||
T: Policy<B, E>,
|
||
P: Policy<B, E>,</div></h4></section></summary><div class='docblock'>Create a new <code>Policy</code> that returns [<code>Action::Follow</code>] if either <code>self</code> or <code>other</code> returns
|
||
<code>Action::Follow</code>. <a>Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Receiver-for-P" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/ops/deref.rs.html#378-380">Source</a><a href="#impl-Receiver-for-P" class="anchor">§</a><h3 class="code-header">impl<P, T> <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Receiver.html" title="trait core::ops::deref::Receiver">Receiver</a> for P<div class="where">where
|
||
P: <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Deref.html" title="trait core::ops::deref::Deref">Deref</a><Target = T> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,
|
||
T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Target-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/ops/deref.rs.html#382">Source</a><a href="#associatedtype.Target-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/ops/deref/trait.Receiver.html#associatedtype.Target" class="associatedtype">Target</a> = T</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>arbitrary_self_types</code>)</span></div></span><div class='docblock'>The target type on which the method may be called.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Same-for-T" class="impl"><a class="src rightside" href="https://docs.rs/typenum/1.20.1/src/typenum/type_operators.rs.html#34">Source</a><a href="#impl-Same-for-T" class="anchor">§</a><h3 class="code-header">impl<T> <a class="trait" href="https://docs.rs/typenum/1.20.1/typenum/type_operators/trait.Same.html" title="trait typenum::type_operators::Same">Same</a> for T</h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Output" class="associatedtype trait-impl"><a class="src rightside" href="https://docs.rs/typenum/1.20.1/src/typenum/type_operators.rs.html#35">Source</a><a href="#associatedtype.Output" class="anchor">§</a><h4 class="code-header">type <a href="https://docs.rs/typenum/1.20.1/typenum/type_operators/trait.Same.html#associatedtype.Output" class="associatedtype">Output</a> = T</h4></section></summary><div class='docblock'>Should always be <code>Self</code></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/nightly/src/core/convert/mod.rs.html#827-829">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#831">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/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/nightly/src/core/convert/mod.rs.html#834">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><T, <T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><U>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></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/nightly/src/core/convert/mod.rs.html#811-813">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl<T, U> <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a><U> for T<div class="where">where
|
||
U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#815">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/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/nightly/src/core/convert/mod.rs.html#818">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -> <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a><U, <U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a><T>>::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>></h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-WithSubscriber-for-T" class="impl"><a href="#impl-WithSubscriber-for-T" class="anchor">§</a><h3 class="code-header">impl<T> WithSubscriber for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.with_subscriber" class="method trait-impl"><a href="#method.with_subscriber" class="anchor">§</a><h4 class="code-header">fn <a class="fn">with_subscriber</a><S>(self, subscriber: S) -> WithDispatch<Self><div class="where">where
|
||
S: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a><Dispatch>,</div></h4></section></summary><div class='docblock'>Attaches the provided <a href="super::Subscriber"><code>Subscriber</code></a> to this type, returning a
|
||
[<code>WithDispatch</code>] wrapper. <a>Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.with_current_subscriber" class="method trait-impl"><a href="#method.with_current_subscriber" class="anchor">§</a><h4 class="code-header">fn <a class="fn">with_current_subscriber</a>(self) -> WithDispatch<Self></h4></section></summary><div class='docblock'>Attaches the current <a href="dispatcher#setting-the-default-subscriber">default</a> <a href="super::Subscriber"><code>Subscriber</code></a> to this type, returning a
|
||
[<code>WithDispatch</code>] wrapper. <a>Read more</a></div></details></div></details></div></section></div></main></body></html> |