blob: 47455e6592e62f2e1916af45d56f07a59594deb8 [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="A structure representing a connected Unix socket."><meta name="keywords" content="rust, rustlang, rust-lang, UnixStream"><title>UnixStream in tokio::net - 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="../../tokio/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="../../tokio/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">UnixStream</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.connect">connect</a></li><li><a href="#method.from_std">from_std</a></li><li><a href="#method.into_split">into_split</a></li><li><a href="#method.into_std">into_std</a></li><li><a href="#method.local_addr">local_addr</a></li><li><a href="#method.pair">pair</a></li><li><a href="#method.peer_addr">peer_addr</a></li><li><a href="#method.peer_cred">peer_cred</a></li><li><a href="#method.poll_read_ready">poll_read_ready</a></li><li><a href="#method.poll_write_ready">poll_write_ready</a></li><li><a href="#method.readable">readable</a></li><li><a href="#method.ready">ready</a></li><li><a href="#method.split">split</a></li><li><a href="#method.take_error">take_error</a></li><li><a href="#method.try_io">try_io</a></li><li><a href="#method.try_read">try_read</a></li><li><a href="#method.try_read_buf">try_read_buf</a></li><li><a href="#method.try_read_vectored">try_read_vectored</a></li><li><a href="#method.try_write">try_write</a></li><li><a href="#method.try_write_vectored">try_write_vectored</a></li><li><a href="#method.writable">writable</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-AsRawFd-for-UnixStream">AsRawFd</a></li><li><a href="#impl-AsRef%3CUnixStream%3E-for-OwnedReadHalf">AsRef&lt;UnixStream&gt;</a></li><li><a href="#impl-AsRef%3CUnixStream%3E-for-OwnedWriteHalf">AsRef&lt;UnixStream&gt;</a></li><li><a href="#impl-AsRef%3CUnixStream%3E-for-ReadHalf%3C%27_%3E">AsRef&lt;UnixStream&gt;</a></li><li><a href="#impl-AsRef%3CUnixStream%3E-for-WriteHalf%3C%27_%3E">AsRef&lt;UnixStream&gt;</a></li><li><a href="#impl-AsyncRead-for-UnixStream">AsyncRead</a></li><li><a href="#impl-AsyncWrite-for-UnixStream">AsyncWrite</a></li><li><a href="#impl-Debug-for-UnixStream">Debug</a></li><li><a href="#impl-TryFrom%3CUnixStream%3E-for-UnixStream">TryFrom&lt;UnixStream&gt;</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-UnixStream">RefUnwindSafe</a></li><li><a href="#impl-Send-for-UnixStream">Send</a></li><li><a href="#impl-Sync-for-UnixStream">Sync</a></li><li><a href="#impl-Unpin-for-UnixStream">Unpin</a></li><li><a href="#impl-UnwindSafe-for-UnixStream">UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-UnixStream">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-UnixStream">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-UnixStream">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-UnixStream">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-UnixStream">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-UnixStream">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-UnixStream">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In tokio::net</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">tokio</a>::<wbr><a href="index.html">net</a>::<wbr><a class="struct" href="#">UnixStream</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/tokio/net/unix/stream.rs.html#36-38">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 UnixStream { /* private fields */ }</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A structure representing a connected Unix socket.</p>
<p>This socket can be connected directly with <a href="struct.UnixStream.html#method.connect" title="UnixStream::connect"><code>UnixStream::connect</code></a> or accepted
from a listener with <a href="struct.UnixListener.html#method.accept"><code>UnixListener::accept</code></a>. Additionally, a pair of
anonymous Unix sockets can be created with <code>UnixStream::pair</code>.</p>
<p>To shut down the stream in the write direction, you can call the
<a href="../io/trait.AsyncWriteExt.html#method.shutdown"><code>shutdown()</code></a> method. This will cause the other peer to receive a read of
length 0, indicating that no more data will be sent. This only closes
the stream in one direction.</p>
</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-UnixStream" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#41-882">source</a><a href="#impl-UnixStream" class="anchor"></a><h3 class="code-header">impl <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.connect" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#47-61">source</a><h4 class="code-header">pub async fn <a href="#method.connect" class="fnname">connect</a>&lt;P&gt;(path: P) -&gt; Result&lt;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;P: AsRef&lt;Path&gt;,</span></h4></section></summary><div class="docblock"><p>Connects to the socket named by <code>path</code>.</p>
<p>This function will create a new Unix socket and connect to the path
specified, associating the returned stream with the default event loop’s
handle.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.ready" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#138-141">source</a><h4 class="code-header">pub async fn <a href="#method.ready" class="fnname">ready</a>(&amp;self, interest: <a class="struct" href="../io/struct.Interest.html" title="struct tokio::io::Interest">Interest</a>) -&gt; Result&lt;<a class="struct" href="../io/struct.Ready.html" title="struct tokio::io::Ready">Ready</a>&gt;</h4></section></summary><div class="docblock"><p>Waits for any of the requested ready states.</p>
<p>This function is usually paired with <code>try_read()</code> or <code>try_write()</code>. It
can be used to concurrently read / write to the same socket on a single
task without splitting the socket.</p>
<p>The function may complete without the socket being ready. This is a
false-positive and attempting an operation will return with
<code>io::ErrorKind::WouldBlock</code>. The function can also return with an empty
<a href="../io/struct.Ready.html" title="Ready"><code>Ready</code></a> set, so you should always check the returned value and possibly
wait again if the requested states are not set.</p>
<h5 id="cancel-safety"><a href="#cancel-safety">Cancel safety</a></h5>
<p>This method is cancel safe. Once a readiness event occurs, the method
will continue to return immediately until the readiness event is
consumed by an attempt to read or write that fails with <code>WouldBlock</code> or
<code>Poll::Pending</code>.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<p>Concurrently read and write to the stream on the same task without
splitting.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::Interest;
<span class="kw">use </span>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="kw">let </span>ready = stream.ready(Interest::READABLE | Interest::WRITABLE).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">if </span>ready.is_readable() {
<span class="kw">let </span><span class="kw-2">mut </span>data = <span class="macro">vec!</span>[<span class="number">0</span>; <span class="number">1024</span>];
<span class="comment">// Try to read data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_read(<span class="kw-2">&amp;mut </span>data) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">&quot;read {} bytes&quot;</span>, n);
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="kw">if </span>ready.is_writable() {
<span class="comment">// Try to write data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_write(<span class="string">b&quot;hello world&quot;</span>) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">&quot;write {} bytes&quot;</span>, n);
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
}
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.readable" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#195-198">source</a><h4 class="code-header">pub async fn <a href="#method.readable" class="fnname">readable</a>(&amp;self) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Waits for the socket to become readable.</p>
<p>This function is equivalent to <code>ready(Interest::READABLE)</code> and is usually
paired with <code>try_read()</code>.</p>
<h5 id="cancel-safety-1"><a href="#cancel-safety-1">Cancel safety</a></h5>
<p>This method is cancel safe. Once a readiness event occurs, the method
will continue to return immediately until the readiness event is
consumed by an attempt to read that fails with <code>WouldBlock</code> or
<code>Poll::Pending</code>.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>msg = <span class="macro">vec!</span>[<span class="number">0</span>; <span class="number">1024</span>];
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>stream.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Try to read data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_read(<span class="kw-2">&amp;mut </span>msg) {
<span class="prelude-val">Ok</span>(n) =&gt; {
msg.truncate(n);
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="macro">println!</span>(<span class="string">&quot;GOT = {:?}&quot;</span>, msg);
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_read_ready" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#229-231">source</a><h4 class="code-header">pub fn <a href="#method.poll_read_ready" class="fnname">poll_read_ready</a>(&amp;self, cx: &amp;mut Context&lt;'_&gt;) -&gt; Poll&lt;Result&lt;()&gt;&gt;</h4></section></summary><div class="docblock"><p>Polls for read readiness.</p>
<p>If the unix stream is not currently ready for reading, this method will
store a clone of the <code>Waker</code> from the provided <code>Context</code>. When the unix
stream becomes ready for reading, <code>Waker::wake</code> will be called on the
waker.</p>
<p>Note that on multiple calls to <code>poll_read_ready</code> or <code>poll_read</code>, only
the <code>Waker</code> from the <code>Context</code> passed to the most recent call is
scheduled to receive a wakeup. (However, <code>poll_write_ready</code> retains a
second, independent waker.)</p>
<p>This function is intended for cases where creating and pinning a future
via <a href="struct.UnixStream.html#method.readable"><code>readable</code></a> is not feasible. Where possible, using <a href="struct.UnixStream.html#method.readable"><code>readable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<h5 id="return-value"><a href="#return-value">Return value</a></h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the unix stream is not ready for reading.</li>
<li><code>Poll::Ready(Ok(()))</code> if the unix stream is ready for reading.</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors"><a href="#errors">Errors</a></h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_read" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#298-302">source</a><h4 class="code-header">pub fn <a href="#method.try_read" class="fnname">try_read</a>(&amp;self, buf: &amp;mut [u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Try to read data from the stream into the provided buffer, returning how
many bytes were read.</p>
<p>Receives any pending data from the socket but does not wait for new data
to arrive. On success, returns the number of bytes read. Because
<code>try_read()</code> is non-blocking, the buffer does not have to be stored by
the async task and can exist entirely on the stack.</p>
<p>Usually, <a href="struct.UnixStream.html#method.readable"><code>readable()</code></a> or <a href="struct.UnixStream.html#method.ready"><code>ready()</code></a> is used with this function.</p>
<h5 id="return"><a href="#return">Return</a></h5>
<p>If data is successfully read, <code>Ok(n)</code> is returned, where <code>n</code> is the
number of bytes read. If <code>n</code> is <code>0</code>, then it can indicate one of two scenarios:</p>
<ol>
<li>The stream’s read half is closed and will no longer yield data.</li>
<li>The specified buffer was 0 bytes in length.</li>
</ol>
<p>If the stream is not ready to read data,
<code>Err(io::ErrorKind::WouldBlock)</code> is returned.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>stream.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Creating the buffer **after** the `await` prevents it from
// being stored in the async task.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf = [<span class="number">0</span>; <span class="number">4096</span>];
<span class="comment">// Try to read data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_read(<span class="kw-2">&amp;mut </span>buf) {
<span class="prelude-val">Ok</span>(<span class="number">0</span>) =&gt; <span class="kw">break</span>,
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">&quot;read {} bytes&quot;</span>, n);
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_read_vectored" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#376-380">source</a><h4 class="code-header">pub fn <a href="#method.try_read_vectored" class="fnname">try_read_vectored</a>(&amp;self, bufs: &amp;mut [IoSliceMut&lt;'_&gt;]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Tries to read data from the stream into the provided buffers, returning
how many bytes were read.</p>
<p>Data is copied to fill each buffer in order, with the final buffer
written to possibly being only partially filled. This method behaves
equivalently to a single call to <a href="struct.UnixStream.html#method.try_read"><code>try_read()</code></a> with concatenated
buffers.</p>
<p>Receives any pending data from the socket but does not wait for new data
to arrive. On success, returns the number of bytes read. Because
<code>try_read_vectored()</code> is non-blocking, the buffer does not have to be
stored by the async task and can exist entirely on the stack.</p>
<p>Usually, <a href="struct.UnixStream.html#method.readable"><code>readable()</code></a> or <a href="struct.UnixStream.html#method.ready"><code>ready()</code></a> is used with this function.</p>
<h5 id="return-1"><a href="#return-1">Return</a></h5>
<p>If data is successfully read, <code>Ok(n)</code> is returned, where <code>n</code> is the
number of bytes read. <code>Ok(0)</code> indicates the stream’s read half is closed
and will no longer yield data. If the stream is not ready to read data
<code>Err(io::ErrorKind::WouldBlock)</code> is returned.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io::{<span class="self">self</span>, IoSliceMut};
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>stream.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Creating the buffer **after** the `await` prevents it from
// being stored in the async task.
</span><span class="kw">let </span><span class="kw-2">mut </span>buf_a = [<span class="number">0</span>; <span class="number">512</span>];
<span class="kw">let </span><span class="kw-2">mut </span>buf_b = [<span class="number">0</span>; <span class="number">1024</span>];
<span class="kw">let </span><span class="kw-2">mut </span>bufs = [
IoSliceMut::new(<span class="kw-2">&amp;mut </span>buf_a),
IoSliceMut::new(<span class="kw-2">&amp;mut </span>buf_b),
];
<span class="comment">// Try to read data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_read_vectored(<span class="kw-2">&amp;mut </span>bufs) {
<span class="prelude-val">Ok</span>(<span class="number">0</span>) =&gt; <span class="kw">break</span>,
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">&quot;read {} bytes&quot;</span>, n);
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_read_buf" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#442-460">source</a><h4 class="code-header">pub fn <a href="#method.try_read_buf" class="fnname">try_read_buf</a>&lt;B:&nbsp;<a class="trait" href="../../bytes/buf/buf_mut/trait.BufMut.html" title="trait bytes::buf::buf_mut::BufMut">BufMut</a>&gt;(&amp;self, buf: &amp;mut B) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Tries to read data from the stream into the provided buffer, advancing the
buffer’s internal cursor, returning how many bytes were read.</p>
<p>Receives any pending data from the socket but does not wait for new data
to arrive. On success, returns the number of bytes read. Because
<code>try_read_buf()</code> is non-blocking, the buffer does not have to be stored by
the async task and can exist entirely on the stack.</p>
<p>Usually, <a href="struct.UnixStream.html#method.readable"><code>readable()</code></a> or <a href="struct.UnixStream.html#method.ready"><code>ready()</code></a> is used with this function.</p>
<h5 id="return-2"><a href="#return-2">Return</a></h5>
<p>If data is successfully read, <code>Ok(n)</code> is returned, where <code>n</code> is the
number of bytes read. <code>Ok(0)</code> indicates the stream’s read half is closed
and will no longer yield data. If the stream is not ready to read data
<code>Err(io::ErrorKind::WouldBlock)</code> is returned.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be readable
</span>stream.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>buf = Vec::with_capacity(<span class="number">4096</span>);
<span class="comment">// Try to read data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_read_buf(<span class="kw-2">&amp;mut </span>buf) {
<span class="prelude-val">Ok</span>(<span class="number">0</span>) =&gt; <span class="kw">break</span>,
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="macro">println!</span>(<span class="string">&quot;read {} bytes&quot;</span>, n);
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.writable" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#511-514">source</a><h4 class="code-header">pub async fn <a href="#method.writable" class="fnname">writable</a>(&amp;self) -&gt; Result&lt;()&gt;</h4></section></summary><div class="docblock"><p>Waits for the socket to become writable.</p>
<p>This function is equivalent to <code>ready(Interest::WRITABLE)</code> and is usually
paired with <code>try_write()</code>.</p>
<h5 id="cancel-safety-2"><a href="#cancel-safety-2">Cancel safety</a></h5>
<p>This method is cancel safe. Once a readiness event occurs, the method
will continue to return immediately until the readiness event is
consumed by an attempt to write that fails with <code>WouldBlock</code> or
<code>Poll::Pending</code>.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be writable
</span>stream.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Try to write data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_write(<span class="string">b&quot;hello world&quot;</span>) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_write_ready" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#545-547">source</a><h4 class="code-header">pub fn <a href="#method.poll_write_ready" class="fnname">poll_write_ready</a>(&amp;self, cx: &amp;mut Context&lt;'_&gt;) -&gt; Poll&lt;Result&lt;()&gt;&gt;</h4></section></summary><div class="docblock"><p>Polls for write readiness.</p>
<p>If the unix stream is not currently ready for writing, this method will
store a clone of the <code>Waker</code> from the provided <code>Context</code>. When the unix
stream becomes ready for writing, <code>Waker::wake</code> will be called on the
waker.</p>
<p>Note that on multiple calls to <code>poll_write_ready</code> or <code>poll_write</code>, only
the <code>Waker</code> from the <code>Context</code> passed to the most recent call is
scheduled to receive a wakeup. (However, <code>poll_read_ready</code> retains a
second, independent waker.)</p>
<p>This function is intended for cases where creating and pinning a future
via <a href="struct.UnixStream.html#method.writable"><code>writable</code></a> is not feasible. Where possible, using <a href="struct.UnixStream.html#method.writable"><code>writable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<h5 id="return-value-1"><a href="#return-value-1">Return value</a></h5>
<p>The function returns:</p>
<ul>
<li><code>Poll::Pending</code> if the unix stream is not ready for writing.</li>
<li><code>Poll::Ready(Ok(()))</code> if the unix stream is ready for writing.</li>
<li><code>Poll::Ready(Err(e))</code> if an error is encountered.</li>
</ul>
<h5 id="errors-1"><a href="#errors-1">Errors</a></h5>
<p>This function may encounter any standard I/O error except <code>WouldBlock</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_write" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#599-603">source</a><h4 class="code-header">pub fn <a href="#method.try_write" class="fnname">try_write</a>(&amp;self, buf: &amp;[u8]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Tries to write a buffer to the stream, returning how many bytes were
written.</p>
<p>The function will attempt to write the entire contents of <code>buf</code>, but
only part of the buffer may be written.</p>
<p>This function is usually paired with <code>writable()</code>.</p>
<h5 id="return-3"><a href="#return-3">Return</a></h5>
<p>If data is successfully written, <code>Ok(n)</code> is returned, where <code>n</code> is the
number of bytes written. If the stream is not ready to write data,
<code>Err(io::ErrorKind::WouldBlock)</code> is returned.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be writable
</span>stream.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Try to write data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_write(<span class="string">b&quot;hello world&quot;</span>) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_write_vectored" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#661-665">source</a><h4 class="code-header">pub fn <a href="#method.try_write_vectored" class="fnname">try_write_vectored</a>(&amp;self, buf: &amp;[IoSlice&lt;'_&gt;]) -&gt; Result&lt;usize&gt;</h4></section></summary><div class="docblock"><p>Tries to write several buffers to the stream, returning how many bytes
were written.</p>
<p>Data is written from each buffer in order, with the final buffer read
from possible being only partially consumed. This method behaves
equivalently to a single call to <a href="struct.UnixStream.html#method.try_write"><code>try_write()</code></a> with concatenated
buffers.</p>
<p>This function is usually paired with <code>writable()</code>.</p>
<h5 id="return-4"><a href="#return-4">Return</a></h5>
<p>If data is successfully written, <code>Ok(n)</code> is returned, where <code>n</code> is the
number of bytes written. If the stream is not ready to write data,
<code>Err(io::ErrorKind::WouldBlock)</code> is returned.</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>tokio::net::UnixStream;
<span class="kw">use </span>std::error::Error;
<span class="kw">use </span>std::io;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="comment">// Connect to a peer
</span><span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span>bufs = [io::IoSlice::new(<span class="string">b&quot;hello &quot;</span>), io::IoSlice::new(<span class="string">b&quot;world&quot;</span>)];
<span class="kw">loop </span>{
<span class="comment">// Wait for the socket to be writable
</span>stream.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="comment">// Try to write data, this may still fail with `WouldBlock`
// if the readiness event is a false positive.
</span><span class="kw">match </span>stream.try_write_vectored(<span class="kw-2">&amp;</span>bufs) {
<span class="prelude-val">Ok</span>(n) =&gt; {
<span class="kw">break</span>;
}
<span class="prelude-val">Err</span>(<span class="kw-2">ref </span>e) <span class="kw">if </span>e.kind() == io::ErrorKind::WouldBlock =&gt; {
<span class="kw">continue</span>;
}
<span class="prelude-val">Err</span>(e) =&gt; {
<span class="kw">return </span><span class="prelude-val">Err</span>(e.into());
}
}
}
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_io" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#699-707">source</a><h4 class="code-header">pub fn <a href="#method.try_io" class="fnname">try_io</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;interest: <a class="struct" href="../io/struct.Interest.html" title="struct tokio::io::Interest">Interest</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;f: impl FnOnce() -&gt; Result&lt;R&gt;<br>) -&gt; Result&lt;R&gt;</h4></section></summary><div class="docblock"><p>Tries to read or write from the socket using a user-provided IO operation.</p>
<p>If the socket is ready, the provided closure is called. The closure
should attempt to perform IO operation on the socket by manually
calling the appropriate syscall. If the operation fails because the
socket is not actually ready, then the closure should return a
<code>WouldBlock</code> error and the readiness flag is cleared. The return value
of the closure is then returned by <code>try_io</code>.</p>
<p>If the socket is not ready, then the closure is not called
and a <code>WouldBlock</code> error is returned.</p>
<p>The closure should only return a <code>WouldBlock</code> error if it has performed
an IO operation on the socket that failed due to the socket not being
ready. Returning a <code>WouldBlock</code> error in any other situation will
incorrectly clear the readiness flag, which can cause the socket to
behave incorrectly.</p>
<p>The closure should not perform the IO operation using any of the methods
defined on the Tokio <code>UnixStream</code> type, as this will mess with the
readiness flag and can cause the socket to behave incorrectly.</p>
<p>This method is not intended to be used with combined interests.
The closure should perform only one type of IO operation, so it should not
require more than one ready state. This method may panic or sleep forever
if it is called with a combined interest.</p>
<p>Usually, <a href="struct.UnixStream.html#method.readable"><code>readable()</code></a>, <a href="struct.UnixStream.html#method.writable"><code>writable()</code></a> or <a href="struct.UnixStream.html#method.ready"><code>ready()</code></a> is used with this function.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from_std" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#725-730">source</a><h4 class="code-header">pub fn <a href="#method.from_std" class="fnname">from_std</a>(stream: UnixStream) -&gt; Result&lt;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>&gt;</h4></section></summary><div class="docblock"><p>Creates new <code>UnixStream</code> from a <code>std::os::unix::net::UnixStream</code>.</p>
<p>This function is intended to be used to wrap a UnixStream from the
standard library in the Tokio equivalent. The conversion assumes
nothing about the underlying stream; it is left up to the user to set
it in non-blocking mode.</p>
<h5 id="panics"><a href="#panics">Panics</a></h5>
<p>This function panics if it is not called from within a runtime with
IO enabled.</p>
<p>The runtime is usually set implicitly when this function is called
from a future driven by a tokio runtime, otherwise runtime can be set
explicitly with <a href="../runtime/struct.Runtime.html#method.enter"><code>Runtime::enter</code></a> function.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_std" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#770-775">source</a><h4 class="code-header">pub fn <a href="#method.into_std" class="fnname">into_std</a>(self) -&gt; Result&lt;UnixStream&gt;</h4></section></summary><div class="docblock"><p>Turns a <a href="struct.UnixStream.html"><code>tokio::net::UnixStream</code></a> into a <a href="std::os::unix::net::UnixStream"><code>std::os::unix::net::UnixStream</code></a>.</p>
<p>The returned <a href="std::os::unix::net::UnixStream"><code>std::os::unix::net::UnixStream</code></a> will have nonblocking
mode set as <code>true</code>. Use <a href="fn@std::os::unix::net::UnixStream::set_nonblocking"><code>set_nonblocking</code></a> to change the blocking
mode if needed.</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>std::error::Error;
<span class="kw">use </span>std::io::Read;
<span class="kw">use </span>tokio::net::UnixListener;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; <span class="prelude-ty">Result</span>&lt;(), Box&lt;<span class="kw">dyn </span>Error&gt;&gt; {
<span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span><span class="kw-2">mut </span>data = [<span class="number">0u8</span>; <span class="number">12</span>];
<span class="kw">let </span>listener = UnixListener::bind(<span class="kw-2">&amp;</span>bind_path)<span class="question-mark">?</span>;
<span class="kw">let </span>(tokio_unix_stream, <span class="kw">_</span>) = listener.accept().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">let </span><span class="kw-2">mut </span>std_unix_stream = tokio_unix_stream.into_std()<span class="question-mark">?</span>;
std_unix_stream.set_nonblocking(<span class="bool-val">false</span>)<span class="question-mark">?</span>;
std_unix_stream.read_exact(<span class="kw-2">&amp;mut </span>data)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.pair" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#782-788">source</a><h4 class="code-header">pub fn <a href="#method.pair" class="fnname">pair</a>() -&gt; Result&lt;(<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>, <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>)&gt;</h4></section></summary><div class="docblock"><p>Creates an unnamed pair of connected sockets.</p>
<p>This function will create a pair of interconnected Unix sockets for
communicating back and forth between one another. Each socket will
be associated with the default event loop’s handle.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.local_addr" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#811-813">source</a><h4 class="code-header">pub fn <a href="#method.local_addr" class="fnname">local_addr</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="unix/struct.SocketAddr.html" title="struct tokio::net::unix::SocketAddr">SocketAddr</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the socket address of the local half of this connection.</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>tokio::net::UnixStream;
<span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">&quot;{:?}&quot;</span>, stream.local_addr()<span class="question-mark">?</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peer_addr" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#831-833">source</a><h4 class="code-header">pub fn <a href="#method.peer_addr" class="fnname">peer_addr</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="unix/struct.SocketAddr.html" title="struct tokio::net::unix::SocketAddr">SocketAddr</a>&gt;</h4></section></summary><div class="docblock"><p>Returns the socket address of the remote half of this connection.</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>tokio::net::UnixStream;
<span class="kw">let </span>dir = tempfile::tempdir().unwrap();
<span class="kw">let </span>bind_path = dir.path().join(<span class="string">&quot;bind_path&quot;</span>);
<span class="kw">let </span>stream = UnixStream::connect(bind_path).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">&quot;{:?}&quot;</span>, stream.peer_addr()<span class="question-mark">?</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.peer_cred" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#836-838">source</a><h4 class="code-header">pub fn <a href="#method.peer_cred" class="fnname">peer_cred</a>(&amp;self) -&gt; Result&lt;<a class="struct" href="unix/struct.UCred.html" title="struct tokio::net::unix::UCred">UCred</a>&gt;</h4></section></summary><div class="docblock"><p>Returns effective credentials of the process which called <code>connect</code> or <code>pair</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.take_error" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#841-843">source</a><h4 class="code-header">pub fn <a href="#method.take_error" class="fnname">take_error</a>(&amp;self) -&gt; Result&lt;Option&lt;Error&gt;&gt;</h4></section></summary><div class="docblock"><p>Returns the value of the <code>SO_ERROR</code> option.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.split" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#864-866">source</a><h4 class="code-header">pub fn <a href="#method.split" class="fnname">split</a>&lt;'a&gt;(&amp;'a mut self) -&gt; (<a class="struct" href="unix/struct.ReadHalf.html" title="struct tokio::net::unix::ReadHalf">ReadHalf</a>&lt;'a&gt;, <a class="struct" href="unix/struct.WriteHalf.html" title="struct tokio::net::unix::WriteHalf">WriteHalf</a>&lt;'a&gt;)</h4></section></summary><div class="docblock"><p>Splits a <code>UnixStream</code> into a read half and a write half, which can be used
to read and write the stream concurrently.</p>
<p>This method is more efficient than <a href="struct.UnixStream.html#method.into_split"><code>into_split</code></a>, but the halves cannot be
moved into independently spawned tasks.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_split" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#879-881">source</a><h4 class="code-header">pub fn <a href="#method.into_split" class="fnname">into_split</a>(self) -&gt; (<a class="struct" href="unix/struct.OwnedReadHalf.html" title="struct tokio::net::unix::OwnedReadHalf">OwnedReadHalf</a>, <a class="struct" href="unix/struct.OwnedWriteHalf.html" title="struct tokio::net::unix::OwnedWriteHalf">OwnedWriteHalf</a>)</h4></section></summary><div class="docblock"><p>Splits a <code>UnixStream</code> into a read half and a write half, which can be used
to read and write the stream concurrently.</p>
<p>Unlike <a href="struct.UnixStream.html#method.split"><code>split</code></a>, the owned halves can be moved to separate tasks, however
this comes at the cost of a heap allocation.</p>
<p><strong>Note:</strong> Dropping the write half will shut down the write half of the
stream. This is equivalent to calling <a href="../io/trait.AsyncWriteExt.html#method.shutdown"><code>shutdown()</code></a> on the <code>UnixStream</code>.</p>
</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-AsRawFd-for-UnixStream" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#976-980">source</a><a href="#impl-AsRawFd-for-UnixStream" class="anchor"></a><h3 class="code-header">impl AsRawFd for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_raw_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#977-979">source</a><a href="#method.as_raw_fd" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_raw_fd</a>(&amp;self) -&gt; RawFd</h4></section></summary><div class='docblock'>Extracts the raw file descriptor. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3CUnixStream%3E-for-OwnedReadHalf" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split_owned.rs.html#399-403">source</a><a href="#impl-AsRef%3CUnixStream%3E-for-OwnedReadHalf" class="anchor"></a><h3 class="code-header">impl AsRef&lt;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>&gt; for <a class="struct" href="unix/struct.OwnedReadHalf.html" title="struct tokio::net::unix::OwnedReadHalf">OwnedReadHalf</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref-2" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split_owned.rs.html#400-402">source</a><a href="#method.as_ref-2" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3CUnixStream%3E-for-OwnedWriteHalf" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split_owned.rs.html#405-409">source</a><a href="#impl-AsRef%3CUnixStream%3E-for-OwnedWriteHalf" class="anchor"></a><h3 class="code-header">impl AsRef&lt;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>&gt; for <a class="struct" href="unix/struct.OwnedWriteHalf.html" title="struct tokio::net::unix::OwnedWriteHalf">OwnedWriteHalf</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref-3" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split_owned.rs.html#406-408">source</a><a href="#method.as_ref-3" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3CUnixStream%3E-for-ReadHalf%3C%27_%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split.rs.html#305-309">source</a><a href="#impl-AsRef%3CUnixStream%3E-for-ReadHalf%3C%27_%3E" class="anchor"></a><h3 class="code-header">impl AsRef&lt;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>&gt; for <a class="struct" href="unix/struct.ReadHalf.html" title="struct tokio::net::unix::ReadHalf">ReadHalf</a>&lt;'_&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split.rs.html#306-308">source</a><a href="#method.as_ref" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRef%3CUnixStream%3E-for-WriteHalf%3C%27_%3E" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split.rs.html#311-315">source</a><a href="#impl-AsRef%3CUnixStream%3E-for-WriteHalf%3C%27_%3E" class="anchor"></a><h3 class="code-header">impl AsRef&lt;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a>&gt; for <a class="struct" href="unix/struct.WriteHalf.html" title="struct tokio::net::unix::WriteHalf">WriteHalf</a>&lt;'_&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_ref-1" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/split.rs.html#312-314">source</a><a href="#method.as_ref-1" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_ref</a>(&amp;self) -&gt; &amp;<a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h4></section></summary><div class='docblock'>Converts this type into a shared reference of the (usually inferred) input type.</div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsyncRead-for-UnixStream" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#896-904">source</a><a href="#impl-AsyncRead-for-UnixStream" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../io/trait.AsyncRead.html" title="trait tokio::io::AsyncRead">AsyncRead</a> for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_read" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#897-903">source</a><a href="#method.poll_read" class="anchor"></a><h4 class="code-header">fn <a href="../io/trait.AsyncRead.html#tymethod.poll_read" class="fnname">poll_read</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;self: Pin&lt;&amp;mut Self&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut Context&lt;'_&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;mut <a class="struct" href="../io/struct.ReadBuf.html" title="struct tokio::io::ReadBuf">ReadBuf</a>&lt;'_&gt;<br>) -&gt; Poll&lt;Result&lt;()&gt;&gt;</h4></section></summary><div class='docblock'>Attempts to read from the <code>AsyncRead</code> into <code>buf</code>. <a href="../io/trait.AsyncRead.html#tymethod.poll_read">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsyncWrite-for-UnixStream" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#906-935">source</a><a href="#impl-AsyncWrite-for-UnixStream" class="anchor"></a><h3 class="code-header">impl <a class="trait" href="../io/trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_write" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#907-913">source</a><a href="#method.poll_write" class="anchor"></a><h4 class="code-header">fn <a href="../io/trait.AsyncWrite.html#tymethod.poll_write" class="fnname">poll_write</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;self: Pin&lt;&amp;mut Self&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut Context&lt;'_&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;[u8]<br>) -&gt; Poll&lt;Result&lt;usize&gt;&gt;</h4></section></summary><div class='docblock'>Attempt to write bytes from <code>buf</code> into the object. <a href="../io/trait.AsyncWrite.html#tymethod.poll_write">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_write_vectored" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#915-921">source</a><a href="#method.poll_write_vectored" class="anchor"></a><h4 class="code-header">fn <a href="../io/trait.AsyncWrite.html#method.poll_write_vectored" class="fnname">poll_write_vectored</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;self: Pin&lt;&amp;mut Self&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut Context&lt;'_&gt;,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;[IoSlice&lt;'_&gt;]<br>) -&gt; Poll&lt;Result&lt;usize&gt;&gt;</h4></section></summary><div class='docblock'>Like <a href="../io/trait.AsyncWrite.html#tymethod.poll_write"><code>poll_write</code></a>, except that it writes from a slice of buffers. <a href="../io/trait.AsyncWrite.html#method.poll_write_vectored">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.is_write_vectored" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#923-925">source</a><a href="#method.is_write_vectored" class="anchor"></a><h4 class="code-header">fn <a href="../io/trait.AsyncWrite.html#method.is_write_vectored" class="fnname">is_write_vectored</a>(&amp;self) -&gt; bool</h4></section></summary><div class='docblock'>Determines if this writer has an efficient <a href="../io/trait.AsyncWrite.html#method.poll_write_vectored"><code>poll_write_vectored</code></a>
implementation. <a href="../io/trait.AsyncWrite.html#method.is_write_vectored">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_flush" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#927-929">source</a><a href="#method.poll_flush" class="anchor"></a><h4 class="code-header">fn <a href="../io/trait.AsyncWrite.html#tymethod.poll_flush" class="fnname">poll_flush</a>(self: Pin&lt;&amp;mut Self&gt;, _: &amp;mut Context&lt;'_&gt;) -&gt; Poll&lt;Result&lt;()&gt;&gt;</h4></section></summary><div class='docblock'>Attempts to flush the object, ensuring that any buffered data reach
their destination. <a href="../io/trait.AsyncWrite.html#tymethod.poll_flush">Read more</a></div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_shutdown" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#931-934">source</a><a href="#method.poll_shutdown" class="anchor"></a><h4 class="code-header">fn <a href="../io/trait.AsyncWrite.html#tymethod.poll_shutdown" class="fnname">poll_shutdown</a>(self: Pin&lt;&amp;mut Self&gt;, _: &amp;mut Context&lt;'_&gt;) -&gt; Poll&lt;Result&lt;()&gt;&gt;</h4></section></summary><div class='docblock'>Initiates or attempts to shut down this writer, returning success when
the I/O connection has completely shut down. <a href="../io/trait.AsyncWrite.html#tymethod.poll_shutdown">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-UnixStream" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#970-974">source</a><a href="#impl-Debug-for-UnixStream" class="anchor"></a><h3 class="code-header">impl Debug for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></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/tokio/net/unix/stream.rs.html#971-973">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-TryFrom%3CUnixStream%3E-for-UnixStream" class="impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#884-894">source</a><a href="#impl-TryFrom%3CUnixStream%3E-for-UnixStream" class="anchor"></a><h3 class="code-header">impl TryFrom&lt;UnixStream&gt; for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../src/tokio/net/unix/stream.rs.html#891-893">source</a><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(stream: UnixStream) -&gt; Result&lt;Self&gt;</h4></section></summary><div class="docblock"><p>Consumes stream, returning the tokio I/O object.</p>
<p>This is equivalent to
<a href="struct.UnixStream.html#method.from_std"><code>UnixStream::from_std(stream)</code></a>.</p>
</div></details><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> = Error</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details></div></details></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-RefUnwindSafe-for-UnixStream" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-UnixStream" class="anchor"></a><h3 class="code-header">impl RefUnwindSafe for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section><section id="impl-Send-for-UnixStream" class="impl has-srclink"><a href="#impl-Send-for-UnixStream" class="anchor"></a><h3 class="code-header">impl Send for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section><section id="impl-Sync-for-UnixStream" class="impl has-srclink"><a href="#impl-Sync-for-UnixStream" class="anchor"></a><h3 class="code-header">impl Sync for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section><section id="impl-Unpin-for-UnixStream" class="impl has-srclink"><a href="#impl-Unpin-for-UnixStream" class="anchor"></a><h3 class="code-header">impl Unpin for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></h3></section><section id="impl-UnwindSafe-for-UnixStream" class="impl has-srclink"><a href="#impl-UnwindSafe-for-UnixStream" class="anchor"></a><h3 class="code-header">impl UnwindSafe for <a class="struct" href="struct.UnixStream.html" title="struct tokio::net::UnixStream">UnixStream</a></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-UnixStream" class="impl has-srclink"><a href="#impl-Any-for-UnixStream" 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-UnixStream" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-UnixStream" 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-UnixStream" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-UnixStream" 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-UnixStream" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-UnixStream" 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-UnixStream" class="impl has-srclink"><a href="#impl-Into%3CU%3E-for-UnixStream" 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-TryFrom%3CU%3E-for-UnixStream" class="impl has-srclink"><a href="#impl-TryFrom%3CU%3E-for-UnixStream" 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-2" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-2" 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-1" 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-1" 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-UnixStream" class="impl has-srclink"><a href="#impl-TryInto%3CU%3E-for-UnixStream" 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-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> = &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="tokio" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>