blob: 772feff94af1be02eb31f98af8ff61e81e4ec34c [file] [log] [blame]
<!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="The receiving side of a channel."><meta name="keywords" content="rust, rustlang, rust-lang, Receiver"><title>Receiver in crossbeam_channel - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc struct"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../crossbeam_channel/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../crossbeam_channel/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Receiver</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.capacity">capacity</a></li><li><a href="#method.is_empty">is_empty</a></li><li><a href="#method.is_full">is_full</a></li><li><a href="#method.iter">iter</a></li><li><a href="#method.len">len</a></li><li><a href="#method.recv">recv</a></li><li><a href="#method.recv_deadline">recv_deadline</a></li><li><a href="#method.recv_timeout">recv_timeout</a></li><li><a href="#method.same_channel">same_channel</a></li><li><a href="#method.try_iter">try_iter</a></li><li><a href="#method.try_recv">try_recv</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Clone-for-Receiver%3CT%3E">Clone</a></li><li><a href="#impl-Debug-for-Receiver%3CT%3E">Debug</a></li><li><a href="#impl-Drop-for-Receiver%3CT%3E">Drop</a></li><li><a href="#impl-IntoIterator-for-%26%27a%20Receiver%3CT%3E">IntoIterator</a></li><li><a href="#impl-IntoIterator-for-Receiver%3CT%3E">IntoIterator</a></li><li><a href="#impl-RefUnwindSafe-for-Receiver%3CT%3E">RefUnwindSafe</a></li><li><a href="#impl-Send-for-Receiver%3CT%3E">Send</a></li><li><a href="#impl-Sync-for-Receiver%3CT%3E">Sync</a></li><li><a href="#impl-UnwindSafe-for-Receiver%3CT%3E">UnwindSafe</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-Unpin-for-Receiver%3CT%3E">Unpin</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-Receiver%3CT%3E">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-Receiver%3CT%3E">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-Receiver%3CT%3E">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-Receiver%3CT%3E">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-Receiver%3CT%3E">Into&lt;U&gt;</a></li><li><a href="#impl-ToOwned-for-Receiver%3CT%3E">ToOwned</a></li><li><a href="#impl-TryFrom%3CU%3E-for-Receiver%3CT%3E">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-Receiver%3CT%3E">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In crossbeam_channel</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Struct <a href="index.html">crossbeam_channel</a>::<wbr><a class="struct" href="#">Receiver</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/crossbeam_channel/channel.rs.html#705-707">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct Receiver&lt;T&gt; { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The receiving side of a channel.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<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;
<span class="kw">let </span>(s, r) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
<span class="kw">let _ </span>= s.send(<span class="number">1</span>);
thread::sleep(Duration::from_secs(<span class="number">1</span>));
<span class="kw">let _ </span>= s.send(<span class="number">2</span>);
});
<span class="macro">assert_eq!</span>(r.recv(), <span class="prelude-val">Ok</span>(<span class="number">1</span>)); <span class="comment">// Received immediately.
</span><span class="macro">assert_eq!</span>(r.recv(), <span class="prelude-val">Ok</span>(<span class="number">2</span>)); <span class="comment">// Received after 1 second.</span></code></pre></div>
</div></details><h2 id="implementations" class="small-section-header">Implementations<a href="#implementations" class="anchor"></a></h2><div id="implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#736-1148">source</a><a href="#impl-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_recv" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#759-782">source</a><h4 class="code-header">pub fn <a href="#method.try_recv" class="fnname">try_recv</a>(&amp;self) -&gt; Result&lt;T, <a class="enum" href="enum.TryRecvError.html" title="enum crossbeam_channel::TryRecvError">TryRecvError</a>&gt;</h4></section></summary><div class="docblock"><p>Attempts to receive a message from the channel without blocking.</p>
<p>This method will either receive a message from the channel immediately or return an error
if the channel is empty.</p>
<p>If called on a zero-capacity channel, this method will receive a message only if there
happens to be a send operation on the other side of the channel at the same time.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::{unbounded, TryRecvError};
<span class="kw">let </span>(s, r) = unbounded();
<span class="macro">assert_eq!</span>(r.try_recv(), <span class="prelude-val">Err</span>(TryRecvError::Empty));
s.send(<span class="number">5</span>).unwrap();
drop(s);
<span class="macro">assert_eq!</span>(r.try_recv(), <span class="prelude-val">Ok</span>(<span class="number">5</span>));
<span class="macro">assert_eq!</span>(r.try_recv(), <span class="prelude-val">Err</span>(TryRecvError::Disconnected));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#812-838">source</a><h4 class="code-header">pub fn <a href="#method.recv" class="fnname">recv</a>(&amp;self) -&gt; Result&lt;T, <a class="struct" href="struct.RecvError.html" title="struct crossbeam_channel::RecvError">RecvError</a>&gt;</h4></section></summary><div class="docblock"><p>Blocks the current thread until a message is received or the channel is empty and
disconnected.</p>
<p>If the channel is empty and not disconnected, this call will block until the receive
operation can proceed. If the channel is empty and becomes disconnected, this call will
wake up and return an error.</p>
<p>If called on a zero-capacity channel, this method will wait for a send operation to appear
on the other side of the channel.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::{unbounded, RecvError};
<span class="kw">let </span>(s, r) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s.send(<span class="number">5</span>).unwrap();
drop(s);
});
<span class="macro">assert_eq!</span>(r.recv(), <span class="prelude-val">Ok</span>(<span class="number">5</span>));
<span class="macro">assert_eq!</span>(r.recv(), <span class="prelude-val">Err</span>(RecvError));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_timeout" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#877-882">source</a><h4 class="code-header">pub fn <a href="#method.recv_timeout" class="fnname">recv_timeout</a>(&amp;self, timeout: Duration) -&gt; Result&lt;T, <a class="enum" href="enum.RecvTimeoutError.html" title="enum crossbeam_channel::RecvTimeoutError">RecvTimeoutError</a>&gt;</h4></section></summary><div class="docblock"><p>Waits for a message to be received from the channel, but only for a limited time.</p>
<p>If the channel is empty and not disconnected, this call will block until the receive
operation can proceed or the operation times out. If the channel is empty and becomes
disconnected, this call will wake up and return an error.</p>
<p>If called on a zero-capacity channel, this method will wait for a send operation to appear
on the other side of the channel.</p>
<h5 id="examples-3"><a href="#examples-3">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::{unbounded, RecvTimeoutError};
<span class="kw">let </span>(s, r) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s.send(<span class="number">5</span>).unwrap();
drop(s);
});
<span class="macro">assert_eq!</span>(
r.recv_timeout(Duration::from_millis(<span class="number">500</span>)),
<span class="prelude-val">Err</span>(RecvTimeoutError::Timeout),
);
<span class="macro">assert_eq!</span>(
r.recv_timeout(Duration::from_secs(<span class="number">1</span>)),
<span class="prelude-val">Ok</span>(<span class="number">5</span>),
);
<span class="macro">assert_eq!</span>(
r.recv_timeout(Duration::from_secs(<span class="number">1</span>)),
<span class="prelude-val">Err</span>(RecvTimeoutError::Disconnected),
);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.recv_deadline" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#923-948">source</a><h4 class="code-header">pub fn <a href="#method.recv_deadline" class="fnname">recv_deadline</a>(&amp;self, deadline: Instant) -&gt; Result&lt;T, <a class="enum" href="enum.RecvTimeoutError.html" title="enum crossbeam_channel::RecvTimeoutError">RecvTimeoutError</a>&gt;</h4></section></summary><div class="docblock"><p>Waits for a message to be received from the channel, but only before a given deadline.</p>
<p>If the channel is empty and not disconnected, this call will block until the receive
operation can proceed or the operation times out. If the channel is empty and becomes
disconnected, this call will wake up and return an error.</p>
<p>If called on a zero-capacity channel, this method will wait for a send operation to appear
on the other side of the channel.</p>
<h5 id="examples-4"><a href="#examples-4">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::thread;
<span class="kw">use </span>std::time::{Instant, Duration};
<span class="kw">use </span>crossbeam_channel::{unbounded, RecvTimeoutError};
<span class="kw">let </span>(s, r) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s.send(<span class="number">5</span>).unwrap();
drop(s);
});
<span class="kw">let </span>now = Instant::now();
<span class="macro">assert_eq!</span>(
r.recv_deadline(now + Duration::from_millis(<span class="number">500</span>)),
<span class="prelude-val">Err</span>(RecvTimeoutError::Timeout),
);
<span class="macro">assert_eq!</span>(
r.recv_deadline(now + Duration::from_millis(<span class="number">1500</span>)),
<span class="prelude-val">Ok</span>(<span class="number">5</span>),
);
<span class="macro">assert_eq!</span>(
r.recv_deadline(now + Duration::from_secs(<span class="number">5</span>)),
<span class="prelude-val">Err</span>(RecvTimeoutError::Disconnected),
);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_empty" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#965-974">source</a><h4 class="code-header">pub fn <a href="#method.is_empty" class="fnname">is_empty</a>(&amp;self) -&gt; bool</h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the channel is empty.</p>
<p>Note: Zero-capacity channels are always empty.</p>
<h5 id="examples-5"><a href="#examples-5">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::unbounded;
<span class="kw">let </span>(s, r) = unbounded();
<span class="macro">assert!</span>(r.is_empty());
s.send(<span class="number">0</span>).unwrap();
<span class="macro">assert!</span>(!r.is_empty());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_full" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#991-1000">source</a><h4 class="code-header">pub fn <a href="#method.is_full" class="fnname">is_full</a>(&amp;self) -&gt; bool</h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the channel is full.</p>
<p>Note: Zero-capacity channels are always full.</p>
<h5 id="examples-6"><a href="#examples-6">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::bounded;
<span class="kw">let </span>(s, r) = bounded(<span class="number">1</span>);
<span class="macro">assert!</span>(!r.is_full());
s.send(<span class="number">0</span>).unwrap();
<span class="macro">assert!</span>(r.is_full());</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.len" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1016-1025">source</a><h4 class="code-header">pub fn <a href="#method.len" class="fnname">len</a>(&amp;self) -&gt; usize</h4></section></summary><div class="docblock"><p>Returns the number of messages in the channel.</p>
<h5 id="examples-7"><a href="#examples-7">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::unbounded;
<span class="kw">let </span>(s, r) = unbounded();
<span class="macro">assert_eq!</span>(r.len(), <span class="number">0</span>);
s.send(<span class="number">1</span>).unwrap();
s.send(<span class="number">2</span>).unwrap();
<span class="macro">assert_eq!</span>(r.len(), <span class="number">2</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.capacity" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1043-1052">source</a><h4 class="code-header">pub fn <a href="#method.capacity" class="fnname">capacity</a>(&amp;self) -&gt; Option&lt;usize&gt;</h4></section></summary><div class="docblock"><p>If the channel is bounded, returns its capacity.</p>
<h5 id="examples-8"><a href="#examples-8">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::{bounded, unbounded};
<span class="kw">let </span>(<span class="kw">_</span>, r) = unbounded::&lt;i32&gt;();
<span class="macro">assert_eq!</span>(r.capacity(), <span class="prelude-val">None</span>);
<span class="kw">let </span>(<span class="kw">_</span>, r) = bounded::&lt;i32&gt;(<span class="number">5</span>);
<span class="macro">assert_eq!</span>(r.capacity(), <span class="prelude-val">Some</span>(<span class="number">5</span>));
<span class="kw">let </span>(<span class="kw">_</span>, r) = bounded::&lt;i32&gt;(<span class="number">0</span>);
<span class="macro">assert_eq!</span>(r.capacity(), <span class="prelude-val">Some</span>(<span class="number">0</span>));</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.iter" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1082-1084">source</a><h4 class="code-header">pub fn <a href="#method.iter" class="fnname">iter</a>(&amp;self) -&gt; <a class="struct" href="struct.Iter.html" title="struct crossbeam_channel::Iter">Iter</a>&lt;'_, T&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.Iter.html" title="struct crossbeam_channel::Iter">Iter</a>&lt;'_, T&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;T&gt; Iterator for <a class="struct" href="struct.Iter.html" title="struct crossbeam_channel::Iter">Iter</a>&lt;'_, T&gt;</span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = T;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>A blocking iterator over messages in the channel.</p>
<p>Each call to <a href="Iterator::next"><code>next</code></a> blocks waiting for the next message and then returns it. However, if
the channel becomes empty and disconnected, it returns [<code>None</code>] without blocking.</p>
<h5 id="examples-9"><a href="#examples-9">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::thread;
<span class="kw">use </span>crossbeam_channel::unbounded;
<span class="kw">let </span>(s, r) = unbounded();
thread::spawn(<span class="kw">move </span>|| {
s.send(<span class="number">1</span>).unwrap();
s.send(<span class="number">2</span>).unwrap();
s.send(<span class="number">3</span>).unwrap();
drop(s); <span class="comment">// Disconnect the channel.
</span>});
<span class="comment">// Collect all messages from the channel.
// Note that the call to `collect` blocks until the sender is dropped.
</span><span class="kw">let </span>v: Vec&lt;<span class="kw">_</span>&gt; = r.iter().collect();
<span class="macro">assert_eq!</span>(v, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_iter" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1118-1120">source</a><h4 class="code-header">pub fn <a href="#method.try_iter" class="fnname">try_iter</a>(&amp;self) -&gt; <a class="struct" href="struct.TryIter.html" title="struct crossbeam_channel::TryIter">TryIter</a>&lt;'_, T&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.TryIter.html" title="struct crossbeam_channel::TryIter">TryIter</a>&lt;'_, T&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;T&gt; Iterator for <a class="struct" href="struct.TryIter.html" title="struct crossbeam_channel::TryIter">TryIter</a>&lt;'_, T&gt;</span><span class="where fmt-newline"> type <a class="associatedtype">Item</a> = T;</span></code></span></span></span></span></h4></section></summary><div class="docblock"><p>A non-blocking iterator over messages in the channel.</p>
<p>Each call to <a href="Iterator::next"><code>next</code></a> returns a message if there is one ready to be received. The iterator
never blocks waiting for the next message.</p>
<h5 id="examples-10"><a href="#examples-10">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::thread;
<span class="kw">use </span>std::time::Duration;
<span class="kw">use </span>crossbeam_channel::unbounded;
<span class="kw">let </span>(s, r) = unbounded::&lt;i32&gt;();
thread::spawn(<span class="kw">move </span>|| {
s.send(<span class="number">1</span>).unwrap();
thread::sleep(Duration::from_secs(<span class="number">1</span>));
s.send(<span class="number">2</span>).unwrap();
thread::sleep(Duration::from_secs(<span class="number">2</span>));
s.send(<span class="number">3</span>).unwrap();
});
thread::sleep(Duration::from_secs(<span class="number">2</span>));
<span class="comment">// Collect all messages from the channel without blocking.
// The third message hasn&#39;t been sent yet so we&#39;ll collect only the first two.
</span><span class="kw">let </span>v: Vec&lt;<span class="kw">_</span>&gt; = r.try_iter().collect();
<span class="macro">assert_eq!</span>(v, [<span class="number">1</span>, <span class="number">2</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.same_channel" class="method has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1137-1147">source</a><h4 class="code-header">pub fn <a href="#method.same_channel" class="fnname">same_channel</a>(&amp;self, other: &amp;<a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;) -&gt; bool</h4></section></summary><div class="docblock"><p>Returns <code>true</code> if receivers belong to the same channel.</p>
<h5 id="examples-11"><a href="#examples-11">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>crossbeam_channel::unbounded;
<span class="kw">let </span>(<span class="kw">_</span>, r) = unbounded::&lt;usize&gt;();
<span class="kw">let </span>r2 = r.clone();
<span class="macro">assert!</span>(r.same_channel(<span class="kw-2">&amp;</span>r2));
<span class="kw">let </span>(<span class="kw">_</span>, r3) = unbounded();
<span class="macro">assert!</span>(!r.same_channel(<span class="kw-2">&amp;</span>r3));</code></pre></div>
</div></details></div></details></div><h2 id="trait-implementations" class="small-section-header">Trait Implementations<a href="#trait-implementations" class="anchor"></a></h2><div id="trait-implementations-list"><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Clone-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1165-1178">source</a><a href="#impl-Clone-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Clone for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1166-1177">source</a><a href="#method.clone" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone</a>(&amp;self) -&gt; Self</h4></section></summary><div class='docblock'>Returns a copy of the value. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_from" class="method trait-impl has-srclink"><span class="since rightside" title="Stable since Rust version 1.0.0">1.0.0</span><a href="#method.clone_from" class="anchor"></a><h4 class="code-header">const fn <a class="fnname">clone_from</a>(&amp;mut self, source: &amp;Self)</h4></section></summary><div class='docblock'>Performs copy-assignment from <code>source</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1180-1184">source</a><a href="#impl-Debug-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Debug for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1181-1183">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&amp;self, f: &amp;mut Formatter&lt;'_&gt;) -&gt; Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Drop-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1150-1163">source</a><a href="#impl-Drop-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Drop for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.drop" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1151-1162">source</a><a href="#method.drop" class="anchor"></a><h4 class="code-header">fn <a class="fnname">drop</a>(&amp;mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-IntoIterator-for-%26%27a%20Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1186-1193">source</a><a href="#impl-IntoIterator-for-%26%27a%20Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;'a, T&gt; IntoIterator for &amp;'a <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Item" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Item" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Item</a> = T</h4></section></summary><div class='docblock'>The type of the elements being iterated over.</div></details><details class="rustdoc-toggle" open><summary><section id="associatedtype.IntoIter" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.IntoIter" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">IntoIter</a> = <a class="struct" href="struct.Iter.html" title="struct crossbeam_channel::Iter">Iter</a>&lt;'a, T&gt;</h4></section></summary><div class='docblock'>Which kind of iterator are we turning this into?</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_iter" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1190-1192">source</a><a href="#method.into_iter" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into_iter</a>(self) -&gt; Self::IntoIter</h4></section></summary><div class='docblock'>Creates an iterator from a value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-IntoIterator-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1195-1202">source</a><a href="#impl-IntoIterator-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; IntoIterator for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Item-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Item-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Item</a> = T</h4></section></summary><div class='docblock'>The type of the elements being iterated over.</div></details><details class="rustdoc-toggle" open><summary><section id="associatedtype.IntoIter-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.IntoIter-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">IntoIter</a> = <a class="struct" href="struct.IntoIter.html" title="struct crossbeam_channel::IntoIter">IntoIter</a>&lt;T&gt;</h4></section></summary><div class='docblock'>Which kind of iterator are we turning this into?</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_iter-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#1199-1201">source</a><a href="#method.into_iter-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">into_iter</a>(self) -&gt; Self::IntoIter</h4></section></summary><div class='docblock'>Creates an iterator from a value. <a>Read more</a></div></details></div></details><section id="impl-RefUnwindSafe-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#734">source</a><a href="#impl-RefUnwindSafe-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; RefUnwindSafe for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section><section id="impl-Send-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#730">source</a><a href="#impl-Send-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;Send&gt; Send for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section><section id="impl-Sync-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#731">source</a><a href="#impl-Sync-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;Send&gt; Sync for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section><section id="impl-UnwindSafe-for-Receiver%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../src/crossbeam_channel/channel.rs.html#733">source</a><a href="#impl-UnwindSafe-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; UnwindSafe for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;</h3></section></div><h2 id="synthetic-implementations" class="small-section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor"></a></h2><div id="synthetic-implementations-list"><section id="impl-Unpin-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-Unpin-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Unpin for <a class="struct" href="struct.Receiver.html" title="struct crossbeam_channel::Receiver">Receiver</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: Unpin,</span></h3></section></div><h2 id="blanket-implementations" class="small-section-header">Blanket Implementations<a href="#blanket-implementations" class="anchor"></a></h2><div id="blanket-implementations-list"><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Any-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-Any-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Any for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.type_id" class="method trait-impl has-srclink"><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a class="fnname">type_id</a>(&amp;self) -&gt; TypeId</h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; Borrow&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow</a>(&amp;self) -&gt; &amp;T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; BorrowMut&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?Sized,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.borrow_mut" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a class="fnname">borrow_mut</a>(&amp;mut self) -&gt; &amp;mut T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; From&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">from</a>(t: T) -&gt; T</h4></section></summary><div class="docblock"><p>Returns the argument unchanged.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Into%3CU%3E-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; Into&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: From&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">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>[From]&lt;T&gt; for U</code> chooses to do.</p>
</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-ToOwned-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-ToOwned-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; ToOwned for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: Clone,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Owned" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Owned" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Owned</a> = T</h4></section></summary><div class='docblock'>The resulting type after obtaining ownership.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.to_owned" class="method trait-impl has-srclink"><a href="#method.to_owned" class="anchor"></a><h4 class="code-header">fn <a class="fnname">to_owned</a>(&amp;self) -&gt; T</h4></section></summary><div class='docblock'>Creates owned data from borrowed data, usually by cloning. <a>Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.clone_into" class="method trait-impl has-srclink"><a href="#method.clone_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">clone_into</a>(&amp;self, target: &amp;mut T)</h4></section></summary><div class='docblock'>Uses borrowed data to replace owned data, usually by cloning. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryFrom%3CU%3E-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryFrom&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: Into&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -&gt; Result&lt;T, &lt;T as TryFrom&lt;U&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-Receiver%3CT%3E" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-Receiver%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; TryInto&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: TryFrom&lt;T&gt;,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = &lt;U as TryFrom&lt;T&gt;&gt;::Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_into</a>(self) -&gt; Result&lt;U, &lt;U as TryFrom&lt;T&gt;&gt;::Error&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="crossbeam_channel" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>