mpvrc/crossbeam_channel/struct.Select.html

415 lines
No EOL
66 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Selects from a set of channel operations."><title>Select in crossbeam_channel - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.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" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="crossbeam_channel" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.1 (e71f9a9a9 2025-01-27)" data-channel="1.84.1" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.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]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../crossbeam_channel/index.html">crossbeam_<wbr>channel</a><span class="version">0.5.13</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Select</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#implementations">Methods</a></h3><ul class="block method"><li><a href="#method.new" title="new">new</a></li><li><a href="#method.ready" title="ready">ready</a></li><li><a href="#method.ready_deadline" title="ready_deadline">ready_deadline</a></li><li><a href="#method.ready_timeout" title="ready_timeout">ready_timeout</a></li><li><a href="#method.recv" title="recv">recv</a></li><li><a href="#method.remove" title="remove">remove</a></li><li><a href="#method.select" title="select">select</a></li><li><a href="#method.select_deadline" title="select_deadline">select_deadline</a></li><li><a href="#method.select_timeout" title="select_timeout">select_timeout</a></li><li><a href="#method.send" title="send">send</a></li><li><a href="#method.try_ready" title="try_ready">try_ready</a></li><li><a href="#method.try_select" title="try_select">try_select</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-Clone-for-Select%3C'a%3E" title="Clone">Clone</a></li><li><a href="#impl-Debug-for-Select%3C'_%3E" title="Debug">Debug</a></li><li><a href="#impl-Default-for-Select%3C'a%3E" title="Default">Default</a></li><li><a href="#impl-Send-for-Select%3C'_%3E" title="Send">Send</a></li><li><a href="#impl-Sync-for-Select%3C'_%3E" title="Sync">Sync</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block synthetic-implementation"><li><a href="#impl-RefUnwindSafe-for-Select%3C'a%3E" title="!RefUnwindSafe">!RefUnwindSafe</a></li><li><a href="#impl-UnwindSafe-for-Select%3C'a%3E" title="!UnwindSafe">!UnwindSafe</a></li><li><a href="#impl-Freeze-for-Select%3C'a%3E" title="Freeze">Freeze</a></li><li><a href="#impl-Unpin-for-Select%3C'a%3E" 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-Borrow%3CT%3E-for-T" title="Borrow&#60;T&#62;">Borrow&#60;T&#62;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-T" title="BorrowMut&#60;T&#62;">BorrowMut&#60;T&#62;</a></li><li><a href="#impl-CloneToUninit-for-T" title="CloneToUninit">CloneToUninit</a></li><li><a href="#impl-From%3CT%3E-for-T" title="From&#60;T&#62;">From&#60;T&#62;</a></li><li><a href="#impl-Into%3CU%3E-for-T" title="Into&#60;U&#62;">Into&#60;U&#62;</a></li><li><a href="#impl-ToOwned-for-T" title="ToOwned">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-T" title="TryFrom&#60;U&#62;">TryFrom&#60;U&#62;</a></li><li><a href="#impl-TryInto%3CU%3E-for-T" title="TryInto&#60;U&#62;">TryInto&#60;U&#62;</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate crossbeam_<wbr>channel</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">crossbeam_channel</a></span><h1>Struct <span class="struct">Select</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/crossbeam_channel/select.rs.html#608-614">Source</a> </span></div><pre class="rust item-decl"><code>pub struct Select&lt;'a&gt; { <span class="comment">/* private fields */</span> }</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Selects from a set of channel operations.</p>
<p><code>Select</code> allows you to define a set of channel operations, wait until any one of them becomes
ready, and finally execute it. If multiple operations are ready at the same time, a random one
among them is selected.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready even
when it will simply return an error because the channel is disconnected.</p>
<p>The <a href="macro.select.html" title="macro crossbeam_channel::select"><code>select!</code></a> macro is a convenience wrapper around <code>Select</code>. However, it cannot select over a
dynamically created list of channel operations.</p>
<p>Once a list of operations has been built with <code>Select</code>, there are two different ways of
proceeding:</p>
<ul>
<li>
<p>Select an operation with <a href="struct.Select.html#method.try_select" title="method crossbeam_channel::Select::try_select"><code>try_select</code></a>, <a href="struct.Select.html#method.select" title="method crossbeam_channel::Select::select"><code>select</code></a>, or <a href="struct.Select.html#method.select_timeout" title="method crossbeam_channel::Select::select_timeout"><code>select_timeout</code></a>. If successful,
the returned selected operation has already begun and <strong>must</strong> be completed. If we dont
complete it, a panic will occur.</p>
</li>
<li>
<p>Wait for an operation to become ready with <a href="struct.Select.html#method.try_ready" title="method crossbeam_channel::Select::try_ready"><code>try_ready</code></a>, <a href="struct.Select.html#method.ready" title="method crossbeam_channel::Select::ready"><code>ready</code></a>, or <a href="struct.Select.html#method.ready_timeout" title="method crossbeam_channel::Select::ready_timeout"><code>ready_timeout</code></a>. If
successful, we may attempt to execute the operation, but are not obliged to. In fact, its
possible for another thread to make the operation not ready just before we try executing it,
so its wise to use a retry loop. However, note that these methods might return with success
spuriously, so its a good idea to always double check if the operation is really ready.</p>
</li>
</ul>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<p>Use <a href="struct.Select.html#method.select" title="method crossbeam_channel::Select::select"><code>select</code></a> to receive a message from a list of receivers:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::{Receiver, RecvError, Select};
<span class="kw">fn </span>recv_multiple&lt;T&gt;(rs: <span class="kw-2">&amp;</span>[Receiver&lt;T&gt;]) -&gt; <span class="prelude-ty">Result</span>&lt;T, RecvError&gt; {
<span class="comment">// Build a list of operations.
</span><span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">for </span>r <span class="kw">in </span>rs {
sel.recv(r);
}
<span class="comment">// Complete the selected operation.
</span><span class="kw">let </span>oper = sel.select();
<span class="kw">let </span>index = oper.index();
oper.recv(<span class="kw-2">&amp;</span>rs[index])
}</code></pre></div>
<p>Use <a href="struct.Select.html#method.ready" title="method crossbeam_channel::Select::ready"><code>ready</code></a> to receive a message from a list of receivers:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::{Receiver, RecvError, Select};
<span class="kw">fn </span>recv_multiple&lt;T&gt;(rs: <span class="kw-2">&amp;</span>[Receiver&lt;T&gt;]) -&gt; <span class="prelude-ty">Result</span>&lt;T, RecvError&gt; {
<span class="comment">// Build a list of operations.
</span><span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">for </span>r <span class="kw">in </span>rs {
sel.recv(r);
}
<span class="kw">loop </span>{
<span class="comment">// Wait until a receive operation becomes ready and try executing it.
</span><span class="kw">let </span>index = sel.ready();
<span class="kw">let </span>res = rs[index].try_recv();
<span class="comment">// If the operation turns out not to be ready, retry.
</span><span class="kw">if let </span><span class="prelude-val">Err</span>(e) = res {
<span class="kw">if </span>e.is_empty() {
<span class="kw">continue</span>;
}
}
<span class="comment">// Success!
</span><span class="kw">return </span>res.map_err(|<span class="kw">_</span>| RecvError);
}
}</code></pre></div>
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Select%3C'a%3E" class="impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#619-1116">Source</a><a href="#impl-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.new" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#632-637">Source</a><h4 class="code-header">pub fn <a href="#method.new" class="fn">new</a>() -&gt; <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h4></section></summary><div class="docblock"><p>Creates an empty list of channel operations for selection.</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>crossbeam_channel::Select;
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="comment">// The list of operations is empty, which means no operation can be selected.
</span><span class="macro">assert!</span>(sel.try_select().is_err());</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.send" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#653-659">Source</a><h4 class="code-header">pub fn <a href="#method.send" class="fn">send</a>&lt;T&gt;(&amp;mut self, s: &amp;'a <a class="struct" href="struct.Sender.html" title="struct crossbeam_channel::Sender">Sender</a>&lt;T&gt;) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Adds a send operation.</p>
<p>Returns the index of the added operation.</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>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s, r) = unbounded::&lt;i32&gt;();
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>index = sel.send(<span class="kw-2">&amp;</span>s);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.recv" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#675-681">Source</a><h4 class="code-header">pub fn <a href="#method.recv" class="fn">recv</a>&lt;T&gt;(&amp;mut self, r: &amp;'a <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Adds a receive operation.</p>
<p>Returns the index of the added operation.</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>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s, r) = unbounded::&lt;i32&gt;();
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>index = sel.recv(<span class="kw-2">&amp;</span>r);</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.remove" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#719-736">Source</a><h4 class="code-header">pub fn <a href="#method.remove" class="fn">remove</a>(&amp;mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Removes a previously added operation.</p>
<p>This is useful when an operation is selected because the channel got disconnected and we
want to try again to select a different operation instead.</p>
<p>If new operations are added after removing some, the indices of removed operations will not
be reused.</p>
<h5 id="panics"><a class="doc-anchor" href="#panics">§</a>Panics</h5>
<p>An attempt to remove a non-existing or already removed operation will panic.</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>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded::&lt;i32&gt;();
<span class="kw">let </span>(<span class="kw">_</span>, r2) = unbounded::&lt;i32&gt;();
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// Both operations are initially ready, so a random one will be executed.
</span><span class="kw">let </span>oper = sel.select();
<span class="macro">assert_eq!</span>(oper.index(), oper2);
<span class="macro">assert!</span>(oper.recv(<span class="kw-2">&amp;</span>r2).is_err());
sel.remove(oper2);
s1.send(<span class="number">10</span>).unwrap();
<span class="kw">let </span>oper = sel.select();
<span class="macro">assert_eq!</span>(oper.index(), oper1);
<span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r1), <span class="prelude-val">Ok</span>(<span class="number">10</span>));</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_select" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#776-778">Source</a><h4 class="code-header">pub fn <a href="#method.try_select" class="fn">try_select</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.SelectedOperation.html" title="struct crossbeam_channel::SelectedOperation">SelectedOperation</a>&lt;'a&gt;, <a class="struct" href="struct.TrySelectError.html" title="struct crossbeam_channel::TrySelectError">TrySelectError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to select one of the operations without blocking.</p>
<p>If an operation is ready, it is selected and returned. If multiple operations are ready at
the same time, a random one among them is selected. If none of the operations are ready, an
error is returned.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>The selected operation must be completed with <a href="struct.SelectedOperation.html#method.send" title="method crossbeam_channel::SelectedOperation::send"><code>SelectedOperation::send</code></a>
or <a href="struct.SelectedOperation.html#method.recv" title="method crossbeam_channel::SelectedOperation::recv"><code>SelectedOperation::recv</code></a>.</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>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
s1.send(<span class="number">10</span>).unwrap();
s2.send(<span class="number">20</span>).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// Both operations are initially ready, so a random one will be executed.
</span><span class="kw">let </span>oper = sel.try_select();
<span class="kw">match </span>oper {
<span class="prelude-val">Err</span>(<span class="kw">_</span>) =&gt; <span class="macro">panic!</span>(<span class="string">"both operations should be ready"</span>),
<span class="prelude-val">Ok</span>(oper) =&gt; <span class="kw">match </span>oper.index() {
i <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r1), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
i <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r2), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
}
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.select" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#823-825">Source</a><h4 class="code-header">pub fn <a href="#method.select" class="fn">select</a>(&amp;mut self) -&gt; <a class="struct" href="struct.SelectedOperation.html" title="struct crossbeam_channel::SelectedOperation">SelectedOperation</a>&lt;'a&gt;</h4></section></summary><div class="docblock"><p>Blocks until one of the operations becomes ready and selects it.</p>
<p>Once an operation becomes ready, it is selected and returned. If multiple operations are
ready at the same time, a random one among them is selected.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>The selected operation must be completed with <a href="struct.SelectedOperation.html#method.send" title="method crossbeam_channel::SelectedOperation::send"><code>SelectedOperation::send</code></a>
or <a href="struct.SelectedOperation.html#method.recv" title="method crossbeam_channel::SelectedOperation::recv"><code>SelectedOperation::recv</code></a>.</p>
<h5 id="panics-1"><a class="doc-anchor" href="#panics-1">§</a>Panics</h5>
<p>Panics if no operations have been added to <code>Select</code>.</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::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s1.send(<span class="number">10</span>).unwrap();
});
thread::spawn(<span class="kw">move </span>|| s2.send(<span class="number">20</span>).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// The second operation will be selected because it becomes ready first.
</span><span class="kw">let </span>oper = sel.select();
<span class="kw">match </span>oper.index() {
i <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r1), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
i <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r2), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.select_timeout" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#870-875">Source</a><h4 class="code-header">pub fn <a href="#method.select_timeout" class="fn">select_timeout</a>(
&amp;mut self,
timeout: <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.SelectedOperation.html" title="struct crossbeam_channel::SelectedOperation">SelectedOperation</a>&lt;'a&gt;, <a class="struct" href="struct.SelectTimeoutError.html" title="struct crossbeam_channel::SelectTimeoutError">SelectTimeoutError</a>&gt;</h4></section></summary><div class="docblock"><p>Blocks for a limited time until one of the operations becomes ready and selects it.</p>
<p>If an operation becomes ready, it is selected and returned. If multiple operations are
ready at the same time, a random one among them is selected. If none of the operations
become ready for the specified duration, an error is returned.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>The selected operation must be completed with <a href="struct.SelectedOperation.html#method.send" title="method crossbeam_channel::SelectedOperation::send"><code>SelectedOperation::send</code></a>
or <a href="struct.SelectedOperation.html#method.recv" title="method crossbeam_channel::SelectedOperation::recv"><code>SelectedOperation::recv</code></a>.</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::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s1.send(<span class="number">10</span>).unwrap();
});
thread::spawn(<span class="kw">move </span>|| s2.send(<span class="number">20</span>).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// The second operation will be selected because it becomes ready first.
</span><span class="kw">let </span>oper = sel.select_timeout(Duration::from_millis(<span class="number">500</span>));
<span class="kw">match </span>oper {
<span class="prelude-val">Err</span>(<span class="kw">_</span>) =&gt; <span class="macro">panic!</span>(<span class="string">"should not have timed out"</span>),
<span class="prelude-val">Ok</span>(oper) =&gt; <span class="kw">match </span>oper.index() {
i <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r1), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
i <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r2), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
}
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.select_deadline" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#922-927">Source</a><h4 class="code-header">pub fn <a href="#method.select_deadline" class="fn">select_deadline</a>(
&amp;mut self,
deadline: <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/time/struct.Instant.html" title="struct std::time::Instant">Instant</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.SelectedOperation.html" title="struct crossbeam_channel::SelectedOperation">SelectedOperation</a>&lt;'a&gt;, <a class="struct" href="struct.SelectTimeoutError.html" title="struct crossbeam_channel::SelectTimeoutError">SelectTimeoutError</a>&gt;</h4></section></summary><div class="docblock"><p>Blocks until a given deadline, or until one of the operations becomes ready and selects it.</p>
<p>If an operation becomes ready, it is selected and returned. If multiple operations are
ready at the same time, a random one among them is selected. If none of the operations
become ready before the given deadline, an error is returned.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>The selected operation must be completed with <a href="struct.SelectedOperation.html#method.send" title="method crossbeam_channel::SelectedOperation::send"><code>SelectedOperation::send</code></a>
or <a href="struct.SelectedOperation.html#method.recv" title="method crossbeam_channel::SelectedOperation::recv"><code>SelectedOperation::recv</code></a>.</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::thread;
<span class="kw">use </span>std::time::{Instant, Duration};
<span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s1.send(<span class="number">10</span>).unwrap();
});
thread::spawn(<span class="kw">move </span>|| s2.send(<span class="number">20</span>).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="kw">let </span>deadline = Instant::now() + Duration::from_millis(<span class="number">500</span>);
<span class="comment">// The second operation will be selected because it becomes ready first.
</span><span class="kw">let </span>oper = sel.select_deadline(deadline);
<span class="kw">match </span>oper {
<span class="prelude-val">Err</span>(<span class="kw">_</span>) =&gt; <span class="macro">panic!</span>(<span class="string">"should not have timed out"</span>),
<span class="prelude-val">Ok</span>(oper) =&gt; <span class="kw">match </span>oper.index() {
i <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r1), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
i <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(oper.recv(<span class="kw-2">&amp;</span>r2), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
}
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.try_ready" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#964-969">Source</a><h4 class="code-header">pub fn <a href="#method.try_ready" class="fn">try_ready</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.TryReadyError.html" title="struct crossbeam_channel::TryReadyError">TryReadyError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to find a ready operation without blocking.</p>
<p>If an operation is ready, its index is returned. If multiple operations are ready at the
same time, a random one among them is chosen. If none of the operations are ready, an error
is returned.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>Note that this method might return with success spuriously, so its a good idea to always
double check if the operation is really ready.</p>
<h5 id="examples-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
s1.send(<span class="number">10</span>).unwrap();
s2.send(<span class="number">20</span>).unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// Both operations are initially ready, so a random one will be chosen.
</span><span class="kw">match </span>sel.try_ready() {
<span class="prelude-val">Err</span>(<span class="kw">_</span>) =&gt; <span class="macro">panic!</span>(<span class="string">"both operations should be ready"</span>),
<span class="prelude-val">Ok</span>(i) <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(r1.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
<span class="prelude-val">Ok</span>(i) <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(r2.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) =&gt; <span class="macro">unreachable!</span>(),
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.ready" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1013-1019">Source</a><h4 class="code-header">pub fn <a href="#method.ready" class="fn">ready</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Blocks until one of the operations becomes ready.</p>
<p>Once an operation becomes ready, its index is returned. If multiple operations are ready at
the same time, a random one among them is chosen.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>Note that this method might return with success spuriously, so its a good idea to always
double check if the operation is really ready.</p>
<h5 id="panics-2"><a class="doc-anchor" href="#panics-2">§</a>Panics</h5>
<p>Panics if no operations have been added to <code>Select</code>.</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::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s1.send(<span class="number">10</span>).unwrap();
});
thread::spawn(<span class="kw">move </span>|| s2.send(<span class="number">20</span>).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// The second operation will be selected because it becomes ready first.
</span><span class="kw">match </span>sel.ready() {
i <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(r1.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
i <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(r2.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.ready_timeout" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1061-1066">Source</a><h4 class="code-header">pub fn <a href="#method.ready_timeout" class="fn">ready_timeout</a>(
&amp;mut self,
timeout: <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.ReadyTimeoutError.html" title="struct crossbeam_channel::ReadyTimeoutError">ReadyTimeoutError</a>&gt;</h4></section></summary><div class="docblock"><p>Blocks for a limited time until one of the operations becomes ready.</p>
<p>If an operation becomes ready, its index is returned. If multiple operations are ready at
the same time, a random one among them is chosen. If none of the operations become ready
for the specified duration, an error is returned.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>Note that this method might return with success spuriously, so its a good idea to double
check if the operation is really ready.</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::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s1.send(<span class="number">10</span>).unwrap();
});
thread::spawn(<span class="kw">move </span>|| s2.send(<span class="number">20</span>).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// The second operation will be selected because it becomes ready first.
</span><span class="kw">match </span>sel.ready_timeout(Duration::from_millis(<span class="number">500</span>)) {
<span class="prelude-val">Err</span>(<span class="kw">_</span>) =&gt; <span class="macro">panic!</span>(<span class="string">"should not have timed out"</span>),
<span class="prelude-val">Ok</span>(i) <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(r1.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
<span class="prelude-val">Ok</span>(i) <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(r2.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) =&gt; <span class="macro">unreachable!</span>(),
}</code></pre></div>
</div></details><details class="toggle method-toggle" open><summary><section id="method.ready_deadline" class="method"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1110-1115">Source</a><h4 class="code-header">pub fn <a href="#method.ready_deadline" class="fn">ready_deadline</a>(
&amp;mut self,
deadline: <a class="struct" href="https://doc.rust-lang.org/1.84.1/std/time/struct.Instant.html" title="struct std::time::Instant">Instant</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.ReadyTimeoutError.html" title="struct crossbeam_channel::ReadyTimeoutError">ReadyTimeoutError</a>&gt;</h4></section></summary><div class="docblock"><p>Blocks until a given deadline, or until one of the operations becomes ready.</p>
<p>If an operation becomes ready, its index is returned. If multiple operations are ready at
the same time, a random one among them is chosen. If none of the operations become ready
before the deadline, an error is returned.</p>
<p>An operation is considered to be ready if it doesnt have to block. Note that it is ready
even when it will simply return an error because the channel is disconnected.</p>
<p>Note that this method might return with success spuriously, so its a good idea to double
check if the operation is really ready.</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::thread;
<span class="kw">use </span>std::time::{Duration, Instant};
<span class="kw">use </span>crossbeam_channel::{unbounded, Select};
<span class="kw">let </span>deadline = Instant::now() + Duration::from_millis(<span class="number">500</span>);
<span class="kw">let </span>(s1, r1) = unbounded();
<span class="kw">let </span>(s2, r2) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s1.send(<span class="number">10</span>).unwrap();
});
thread::spawn(<span class="kw">move </span>|| s2.send(<span class="number">20</span>).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>sel = Select::new();
<span class="kw">let </span>oper1 = sel.recv(<span class="kw-2">&amp;</span>r1);
<span class="kw">let </span>oper2 = sel.recv(<span class="kw-2">&amp;</span>r2);
<span class="comment">// The second operation will be selected because it becomes ready first.
</span><span class="kw">match </span>sel.ready_deadline(deadline) {
<span class="prelude-val">Err</span>(<span class="kw">_</span>) =&gt; <span class="macro">panic!</span>(<span class="string">"should not have timed out"</span>),
<span class="prelude-val">Ok</span>(i) <span class="kw">if </span>i == oper1 =&gt; <span class="macro">assert_eq!</span>(r1.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">10</span>)),
<span class="prelude-val">Ok</span>(i) <span class="kw">if </span>i == oper2 =&gt; <span class="macro">assert_eq!</span>(r2.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">20</span>)),
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) =&gt; <span class="macro">unreachable!</span>(),
}</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Clone-for-Select%3C'a%3E" class="impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1118-1125">Source</a><a href="#impl-Clone-for-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1119-1124">Source</a><a href="#method.clone" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html#tymethod.clone" class="fn">clone</a>(&amp;self) -&gt; <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h4></section></summary><div class='docblock'>Returns a copy of the value. <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html#tymethod.clone">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl"><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/1.84.1/src/core/clone.rs.html#174">Source</a></span><a href="#method.clone_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html#method.clone_from" class="fn">clone_from</a>(&amp;mut self, source: &amp;Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html#method.clone_from">Read more</a></div></details></div></details><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-Select%3C'_%3E" class="impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1133-1137">Source</a><a href="#impl-Debug-for-Select%3C'_%3E" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'_&gt;</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/crossbeam_channel/select.rs.html#1134-1136">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/1.84.1/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/1.84.1/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-Select%3C'a%3E" class="impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1127-1131">Source</a><a href="#impl-Default-for-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html" title="trait core::default::Default">Default</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.default" class="method trait-impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#1128-1130">Source</a><a href="#method.default" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html#tymethod.default" class="fn">default</a>() -&gt; <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h4></section></summary><div class='docblock'>Returns the “default value” for a type. <a href="https://doc.rust-lang.org/1.84.1/core/default/trait.Default.html#tymethod.default">Read more</a></div></details></div></details><section id="impl-Send-for-Select%3C'_%3E" class="impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#616">Source</a><a href="#impl-Send-for-Select%3C'_%3E" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'_&gt;</h3></section><section id="impl-Sync-for-Select%3C'_%3E" class="impl"><a class="src rightside" href="../src/crossbeam_channel/select.rs.html#617">Source</a><a href="#impl-Sync-for-Select%3C'_%3E" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'_&gt;</h3></section></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-Select%3C'a%3E" class="impl"><a href="#impl-Freeze-for-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section><section id="impl-RefUnwindSafe-for-Select%3C'a%3E" class="impl"><a href="#impl-RefUnwindSafe-for-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section><section id="impl-Unpin-for-Select%3C'a%3E" class="impl"><a href="#impl-Unpin-for-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section><section id="impl-UnwindSafe-for-Select%3C'a%3E" class="impl"><a href="#impl-UnwindSafe-for-Select%3C'a%3E" class="anchor">§</a><h3 class="code-header">impl&lt;'a&gt; !<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.Select.html" title="struct crossbeam_channel::Select">Select</a>&lt;'a&gt;</h3></section></div><h2 id="blanket-implementations" class="section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor">§</a></h2><div id="blanket-implementations-list"><details class="toggle implementors-toggle"><summary><section id="impl-Any-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/any.rs.html#138">Source</a><a href="#impl-Any-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<div class="where">where
T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/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/1.84.1/core/any/trait.Any.html#tymethod.type_id" class="fn">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/1.84.1/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/1.84.1/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#209">Source</a><a href="#impl-Borrow%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#211">Source</a><a href="#method.borrow" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow" class="fn">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;T</a></h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#217">Source</a><a href="#impl-BorrowMut%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T<div class="where">where
T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/borrow.rs.html#218">Source</a><a href="#method.borrow_mut" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fn">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a></h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/1.84.1/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-CloneToUninit-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/clone.rs.html#273">Source</a><a href="#impl-CloneToUninit-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.CloneToUninit.html" title="trait core::clone::CloneToUninit">CloneToUninit</a> for T<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.clone_to_uninit" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/clone.rs.html#275">Source</a><a href="#method.clone_to_uninit" class="anchor">§</a><h4 class="code-header">unsafe fn <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit" class="fn">clone_to_uninit</a>(&amp;self, dst: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.pointer.html">*mut </a><a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.u8.html">u8</a>)</h4></section></summary><span class="item-info"><div class="stab unstable"><span class="emoji">🔬</span><span>This is a nightly-only experimental API. (<code>clone_to_uninit</code>)</span></div></span><div class='docblock'>Performs copy-assignment from <code>self</code> to <code>dst</code>. <a href="https://doc.rust-lang.org/1.84.1/core/clone/trait.CloneToUninit.html#tymethod.clone_to_uninit">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#765">Source</a><a href="#impl-From%3CT%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#768">Source</a><a href="#method.from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html#tymethod.from" class="fn">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#748-750">Source</a><a href="#impl-Into%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T<div class="where">where
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt;,</div></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#758">Source</a><a href="#method.into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html#tymethod.into" class="fn">into</a>(self) -&gt; U</h4></section></summary><div class="docblock"><p>Calls <code>U::from(self)</code>.</p>
<p>That is, this conversion is whatever the implementation of
<code><a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-ToOwned-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/borrow.rs.html#82-84">Source</a><a href="#impl-ToOwned-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html" title="trait alloc::borrow::ToOwned">ToOwned</a> for T<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/borrow.rs.html#86">Source</a><a href="#associatedtype.Owned" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#associatedtype.Owned" class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/borrow.rs.html#87">Source</a><a href="#method.to_owned" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned" class="fn">to_owned</a>(&amp;self) -&gt; T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#tymethod.to_owned">Read more</a></div></details><details class="toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/alloc/borrow.rs.html#91">Source</a><a href="#method.clone_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#method.clone_into" class="fn">clone_into</a>(&amp;self, target: <a class="primitive" href="https://doc.rust-lang.org/1.84.1/std/primitive.reference.html">&amp;mut T</a>)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a href="https://doc.rust-lang.org/1.84.1/alloc/borrow/trait.ToOwned.html#method.clone_into">Read more</a></div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#805-807">Source</a><a href="#impl-TryFrom%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T<div class="where">where
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;T&gt;,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#809">Source</a><a href="#associatedtype.Error-1" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#812">Source</a><a href="#method.try_from" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#tymethod.try_from" class="fn">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-T" class="impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#790-792">Source</a><a href="#impl-TryInto%3CU%3E-for-T" class="anchor">§</a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T<div class="where">where
U: <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;,</div></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#794">Source</a><a href="#associatedtype.Error" class="anchor">§</a><h4 class="code-header">type <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl"><a class="src rightside" href="https://doc.rust-lang.org/1.84.1/src/core/convert/mod.rs.html#797">Source</a><a href="#method.try_into" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryInto.html#tymethod.try_into" class="fn">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.1/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.1/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main></body></html>