blob: 70799c12b1454bbf8517390c812d0782482756ae [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="Associates an IO object backed by a Unix file descriptor with the tokio reactor, allowing for readiness to be polled. The file descriptor must be of a type that can be used with the OS polling facilities (ie, `poll`, `epoll`, `kqueue`, etc), such as a network socket or pipe, and the file descriptor must have the nonblocking mode set to true."><meta name="keywords" content="rust, rustlang, rust-lang, AsyncFd"><title>AsyncFd in tokio::io::unix - 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="#">AsyncFd</a></h2><div class="sidebar-elems"><section><h3><a href="#implementations">Methods</a></h3><ul class="block"><li><a href="#method.async_io">async_io</a></li><li><a href="#method.async_io_mut">async_io_mut</a></li><li><a href="#method.get_mut">get_mut</a></li><li><a href="#method.get_ref">get_ref</a></li><li><a href="#method.into_inner">into_inner</a></li><li><a href="#method.new">new</a></li><li><a href="#method.poll_read_ready">poll_read_ready</a></li><li><a href="#method.poll_read_ready_mut">poll_read_ready_mut</a></li><li><a href="#method.poll_write_ready">poll_write_ready</a></li><li><a href="#method.poll_write_ready_mut">poll_write_ready_mut</a></li><li><a href="#method.readable">readable</a></li><li><a href="#method.readable_mut">readable_mut</a></li><li><a href="#method.with_interest">with_interest</a></li><li><a href="#method.writable">writable</a></li><li><a href="#method.writable_mut">writable_mut</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block"><li><a href="#impl-AsFd-for-AsyncFd%3CT%3E">AsFd</a></li><li><a href="#impl-AsRawFd-for-AsyncFd%3CT%3E">AsRawFd</a></li><li><a href="#impl-Debug-for-AsyncFd%3CT%3E">Debug</a></li><li><a href="#impl-Drop-for-AsyncFd%3CT%3E">Drop</a></li></ul><h3><a href="#synthetic-implementations">Auto Trait Implementations</a></h3><ul class="block"><li><a href="#impl-RefUnwindSafe-for-AsyncFd%3CT%3E">!RefUnwindSafe</a></li><li><a href="#impl-Send-for-AsyncFd%3CT%3E">Send</a></li><li><a href="#impl-Sync-for-AsyncFd%3CT%3E">Sync</a></li><li><a href="#impl-Unpin-for-AsyncFd%3CT%3E">Unpin</a></li><li><a href="#impl-UnwindSafe-for-AsyncFd%3CT%3E">!UnwindSafe</a></li></ul><h3><a href="#blanket-implementations">Blanket Implementations</a></h3><ul class="block"><li><a href="#impl-Any-for-AsyncFd%3CT%3E">Any</a></li><li><a href="#impl-Borrow%3CT%3E-for-AsyncFd%3CT%3E">Borrow&lt;T&gt;</a></li><li><a href="#impl-BorrowMut%3CT%3E-for-AsyncFd%3CT%3E">BorrowMut&lt;T&gt;</a></li><li><a href="#impl-From%3CT%3E-for-AsyncFd%3CT%3E">From&lt;T&gt;</a></li><li><a href="#impl-Into%3CU%3E-for-AsyncFd%3CT%3E">Into&lt;U&gt;</a></li><li><a href="#impl-TryFrom%3CU%3E-for-AsyncFd%3CT%3E">TryFrom&lt;U&gt;</a></li><li><a href="#impl-TryInto%3CU%3E-for-AsyncFd%3CT%3E">TryInto&lt;U&gt;</a></li></ul></section><h2><a href="index.html">In tokio::io::unix</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">io</a>::<wbr><a href="index.html">unix</a>::<wbr><a class="struct" href="#">AsyncFd</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/io/async_fd.rs.html#177-180">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 AsyncFd&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>&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>Associates an IO object backed by a Unix file descriptor with the tokio
reactor, allowing for readiness to be polled. The file descriptor must be of
a type that can be used with the OS polling facilities (ie, <code>poll</code>, <code>epoll</code>,
<code>kqueue</code>, etc), such as a network socket or pipe, and the file descriptor
must have the nonblocking mode set to true.</p>
<p>Creating an AsyncFd registers the file descriptor with the current tokio
Reactor, allowing you to directly await the file descriptor being readable
or writable. Once registered, the file descriptor remains registered until
the AsyncFd is dropped.</p>
<p>The AsyncFd takes ownership of an arbitrary object to represent the IO
object. It is intended that this object will handle closing the file
descriptor when it is dropped, avoiding resource leaks and ensuring that the
AsyncFd can clean up the registration before closing the file descriptor.
The <a href="struct.AsyncFd.html#method.into_inner" title="AsyncFd::into_inner"><code>AsyncFd::into_inner</code></a> function can be used to extract the inner object
to retake control from the tokio IO reactor.</p>
<p>The inner object is required to implement <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="AsRawFd"><code>AsRawFd</code></a>. This file descriptor
must not change while <a href="struct.AsyncFd.html" title="AsyncFd"><code>AsyncFd</code></a> owns the inner object, i.e. the
<a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd" title="AsRawFd::as_raw_fd"><code>AsRawFd::as_raw_fd</code></a> method on the inner type must always return the same
file descriptor when called multiple times. Failure to uphold this results
in unspecified behavior in the IO driver, which may include breaking
notifications for other sockets/etc.</p>
<p>Polling for readiness is done by calling the async functions <a href="struct.AsyncFd.html#method.readable"><code>readable</code></a>
and <a href="struct.AsyncFd.html#method.writable"><code>writable</code></a>. These functions complete when the associated readiness
condition is observed. Any number of tasks can query the same <code>AsyncFd</code> in
parallel, on the same or different conditions.</p>
<p>On some platforms, the readiness detecting mechanism relies on
edge-triggered notifications. This means that the OS will only notify Tokio
when the file descriptor transitions from not-ready to ready. For this to
work you should first try to read or write and only poll for readiness
if that fails with an error of <a href="https://doc.rust-lang.org/nightly/std/io/error/enum.ErrorKind.html#variant.WouldBlock" title="std::io::ErrorKind::WouldBlock"><code>std::io::ErrorKind::WouldBlock</code></a>.</p>
<p>Tokio internally tracks when it has received a ready notification, and when
readiness checking functions like <a href="struct.AsyncFd.html#method.readable"><code>readable</code></a> and <a href="struct.AsyncFd.html#method.writable"><code>writable</code></a> are called,
if the readiness flag is set, these async functions will complete
immediately. This however does mean that it is critical to ensure that this
ready flag is cleared when (and only when) the file descriptor ceases to be
ready. The <a href="struct.AsyncFdReadyGuard.html"><code>AsyncFdReadyGuard</code></a> returned from readiness checking functions
serves this function; after calling a readiness-checking async function,
you must use this <a href="struct.AsyncFdReadyGuard.html"><code>AsyncFdReadyGuard</code></a> to signal to tokio whether the file
descriptor is no longer in a ready state.</p>
<h3 id="use-with-to-a-poll-based-api"><a href="#use-with-to-a-poll-based-api">Use with to a poll-based API</a></h3>
<p>In some cases it may be desirable to use <code>AsyncFd</code> from APIs similar to
<a href="../../net/struct.TcpStream.html"><code>TcpStream::poll_read_ready</code></a>. The <a href="struct.AsyncFd.html#method.poll_read_ready" title="AsyncFd::poll_read_ready"><code>AsyncFd::poll_read_ready</code></a> and
<a href="struct.AsyncFd.html#method.poll_write_ready" title="AsyncFd::poll_write_ready"><code>AsyncFd::poll_write_ready</code></a> functions are provided for this purpose.
Because these functions don’t create a future to hold their state, they have
the limitation that only one task can wait on each direction (read or write)
at a time.</p>
<h2 id="examples"><a href="#examples">Examples</a></h2>
<p>This example shows how to turn <a href="https://doc.rust-lang.org/nightly/std/net/tcp/struct.TcpStream.html" title="std::net::TcpStream"><code>std::net::TcpStream</code></a> asynchronous using
<code>AsyncFd</code>. It implements the read/write operations both as an <code>async fn</code>
and using the IO traits <a href="../trait.AsyncRead.html"><code>AsyncRead</code></a> and <a href="../trait.AsyncWrite.html"><code>AsyncWrite</code></a>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::ready;
<span class="kw">use </span>std::io::{<span class="self">self</span>, Read, Write};
<span class="kw">use </span>std::net::TcpStream;
<span class="kw">use </span>std::pin::Pin;
<span class="kw">use </span>std::task::{Context, Poll};
<span class="kw">use </span>tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
<span class="kw">use </span>tokio::io::unix::AsyncFd;
<span class="kw">pub struct </span>AsyncTcpStream {
inner: AsyncFd&lt;TcpStream&gt;,
}
<span class="kw">impl </span>AsyncTcpStream {
<span class="kw">pub fn </span>new(tcp: TcpStream) -&gt; io::Result&lt;<span class="self">Self</span>&gt; {
tcp.set_nonblocking(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
<span class="prelude-val">Ok</span>(<span class="self">Self </span>{
inner: AsyncFd::new(tcp)<span class="question-mark">?</span>,
})
}
<span class="kw">pub async fn </span>read(<span class="kw-2">&amp;</span><span class="self">self</span>, out: <span class="kw-2">&amp;mut </span>[u8]) -&gt; io::Result&lt;usize&gt; {
<span class="kw">loop </span>{
<span class="kw">let </span><span class="kw-2">mut </span>guard = <span class="self">self</span>.inner.readable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">match </span>guard.try_io(|inner| inner.get_ref().read(out)) {
<span class="prelude-val">Ok</span>(result) =&gt; <span class="kw">return </span>result,
<span class="prelude-val">Err</span>(_would_block) =&gt; <span class="kw">continue</span>,
}
}
}
<span class="kw">pub async fn </span>write(<span class="kw-2">&amp;</span><span class="self">self</span>, buf: <span class="kw-2">&amp;</span>[u8]) -&gt; io::Result&lt;usize&gt; {
<span class="kw">loop </span>{
<span class="kw">let </span><span class="kw-2">mut </span>guard = <span class="self">self</span>.inner.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">match </span>guard.try_io(|inner| inner.get_ref().write(buf)) {
<span class="prelude-val">Ok</span>(result) =&gt; <span class="kw">return </span>result,
<span class="prelude-val">Err</span>(_would_block) =&gt; <span class="kw">continue</span>,
}
}
}
}
<span class="kw">impl </span>AsyncRead <span class="kw">for </span>AsyncTcpStream {
<span class="kw">fn </span>poll_read(
<span class="self">self</span>: Pin&lt;<span class="kw-2">&amp;mut </span><span class="self">Self</span>&gt;,
cx: <span class="kw-2">&amp;mut </span>Context&lt;<span class="lifetime">&#39;_</span>&gt;,
buf: <span class="kw-2">&amp;mut </span>ReadBuf&lt;<span class="lifetime">&#39;_</span>&gt;
) -&gt; Poll&lt;io::Result&lt;()&gt;&gt; {
<span class="kw">loop </span>{
<span class="kw">let </span><span class="kw-2">mut </span>guard = <span class="macro">ready!</span>(<span class="self">self</span>.inner.poll_read_ready(cx))<span class="question-mark">?</span>;
<span class="kw">let </span>unfilled = buf.initialize_unfilled();
<span class="kw">match </span>guard.try_io(|inner| inner.get_ref().read(unfilled)) {
<span class="prelude-val">Ok</span>(<span class="prelude-val">Ok</span>(len)) =&gt; {
buf.advance(len);
<span class="kw">return </span>Poll::Ready(<span class="prelude-val">Ok</span>(()));
},
<span class="prelude-val">Ok</span>(<span class="prelude-val">Err</span>(err)) =&gt; <span class="kw">return </span>Poll::Ready(<span class="prelude-val">Err</span>(err)),
<span class="prelude-val">Err</span>(_would_block) =&gt; <span class="kw">continue</span>,
}
}
}
}
<span class="kw">impl </span>AsyncWrite <span class="kw">for </span>AsyncTcpStream {
<span class="kw">fn </span>poll_write(
<span class="self">self</span>: Pin&lt;<span class="kw-2">&amp;mut </span><span class="self">Self</span>&gt;,
cx: <span class="kw-2">&amp;mut </span>Context&lt;<span class="lifetime">&#39;_</span>&gt;,
buf: <span class="kw-2">&amp;</span>[u8]
) -&gt; Poll&lt;io::Result&lt;usize&gt;&gt; {
<span class="kw">loop </span>{
<span class="kw">let </span><span class="kw-2">mut </span>guard = <span class="macro">ready!</span>(<span class="self">self</span>.inner.poll_write_ready(cx))<span class="question-mark">?</span>;
<span class="kw">match </span>guard.try_io(|inner| inner.get_ref().write(buf)) {
<span class="prelude-val">Ok</span>(result) =&gt; <span class="kw">return </span>Poll::Ready(result),
<span class="prelude-val">Err</span>(_would_block) =&gt; <span class="kw">continue</span>,
}
}
}
<span class="kw">fn </span>poll_flush(
<span class="self">self</span>: Pin&lt;<span class="kw-2">&amp;mut </span><span class="self">Self</span>&gt;,
cx: <span class="kw-2">&amp;mut </span>Context&lt;<span class="lifetime">&#39;_</span>&gt;,
) -&gt; Poll&lt;io::Result&lt;()&gt;&gt; {
<span class="comment">// tcp flush is a no-op
</span>Poll::Ready(<span class="prelude-val">Ok</span>(()))
}
<span class="kw">fn </span>poll_shutdown(
<span class="self">self</span>: Pin&lt;<span class="kw-2">&amp;mut </span><span class="self">Self</span>&gt;,
cx: <span class="kw-2">&amp;mut </span>Context&lt;<span class="lifetime">&#39;_</span>&gt;,
) -&gt; Poll&lt;io::Result&lt;()&gt;&gt; {
<span class="self">self</span>.inner.get_ref().shutdown(std::net::Shutdown::Write)<span class="question-mark">?</span>;
Poll::Ready(<span class="prelude-val">Ok</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-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#206-614">source</a><a href="#impl-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>&gt; <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.new" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#219-224">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(inner: T) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;Self&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>,</span></h4></section></summary><div class="docblock"><p>Creates an AsyncFd backed by (and taking ownership of) an object
implementing <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="AsRawFd"><code>AsRawFd</code></a>. The backing file descriptor is cached at the
time of creation.</p>
<p>This method must be called in the context of a tokio runtime.</p>
<h5 id="panics"><a href="#panics">Panics</a></h5>
<p>This function panics if there is no current reactor set, or if the <code>rt</code>
feature flag is not enabled.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.with_interest" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#235-240">source</a><h4 class="code-header">pub fn <a href="#method.with_interest" class="fnname">with_interest</a>(inner: T, interest: <a class="struct" href="../struct.Interest.html" title="struct tokio::io::Interest">Interest</a>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;Self&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>,</span></h4></section></summary><div class="docblock"><p>Creates new instance as <code>new</code> with additional ability to customize interest,
allowing to specify whether file descriptor will be polled for read, write or both.</p>
<h5 id="panics-1"><a href="#panics-1">Panics</a></h5>
<p>This function panics if there is no current reactor set, or if the <code>rt</code>
feature flag is not enabled.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_ref" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#261-263">source</a><h4 class="code-header">pub fn <a href="#method.get_ref" class="fnname">get_ref</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</h4></section></summary><div class="docblock"><p>Returns a shared reference to the backing object of this <a href="struct.AsyncFd.html" title="AsyncFd"><code>AsyncFd</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.get_mut" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#267-269">source</a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fnname">get_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</h4></section></summary><div class="docblock"><p>Returns a mutable reference to the backing object of this <a href="struct.AsyncFd.html" title="AsyncFd"><code>AsyncFd</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_inner" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#283-285">source</a><h4 class="code-header">pub fn <a href="#method.into_inner" class="fnname">into_inner</a>(self) -&gt; T</h4></section></summary><div class="docblock"><p>Deregisters this file descriptor and returns ownership of the backing
object.</p>
</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/io/async_fd.rs.html#314-325">source</a><h4 class="code-header">pub fn <a href="#method.poll_read_ready" class="fnname">poll_read_ready</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a>&lt;'a, T&gt;&gt;&gt;</h4></section></summary><div class="docblock"><p>Polls for read readiness.</p>
<p>If the file descriptor is not currently ready for reading, this method
will store a clone of the <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html"><code>Waker</code></a> from the provided <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html"><code>Context</code></a>. When the
file descriptor becomes ready for reading, <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html#method.wake"><code>Waker::wake</code></a> will be called.</p>
<p>Note that on multiple calls to <a href="struct.AsyncFd.html#method.poll_read_ready"><code>poll_read_ready</code></a> or
<a href="struct.AsyncFd.html#method.poll_read_ready_mut"><code>poll_read_ready_mut</code></a>, only the <code>Waker</code> from the <code>Context</code> passed to the
most recent call is scheduled to receive a wakeup. (However,
<a href="struct.AsyncFd.html#method.poll_write_ready"><code>poll_write_ready</code></a> retains a second, independent waker).</p>
<p>This method is intended for cases where creating and pinning a future
via <a href="struct.AsyncFd.html#method.readable"><code>readable</code></a> is not feasible. Where possible, using <a href="struct.AsyncFd.html#method.readable"><code>readable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<p>This method takes <code>&amp;self</code>, so it is possible to call this method
concurrently with other methods on this struct. This method only
provides shared access to the inner IO resource when handling the
<a href="struct.AsyncFdReadyGuard.html" title="AsyncFdReadyGuard"><code>AsyncFdReadyGuard</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_read_ready_mut" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#352-363">source</a><h4 class="code-header">pub fn <a href="#method.poll_read_ready_mut" class="fnname">poll_read_ready_mut</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a>&lt;'a, T&gt;&gt;&gt;</h4></section></summary><div class="docblock"><p>Polls for read readiness.</p>
<p>If the file descriptor is not currently ready for reading, this method
will store a clone of the <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html"><code>Waker</code></a> from the provided <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html"><code>Context</code></a>. When the
file descriptor becomes ready for reading, <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html#method.wake"><code>Waker::wake</code></a> will be called.</p>
<p>Note that on multiple calls to <a href="struct.AsyncFd.html#method.poll_read_ready"><code>poll_read_ready</code></a> or
<a href="struct.AsyncFd.html#method.poll_read_ready_mut"><code>poll_read_ready_mut</code></a>, only the <code>Waker</code> from the <code>Context</code> passed to the
most recent call is scheduled to receive a wakeup. (However,
<a href="struct.AsyncFd.html#method.poll_write_ready"><code>poll_write_ready</code></a> retains a second, independent waker).</p>
<p>This method is intended for cases where creating and pinning a future
via <a href="struct.AsyncFd.html#method.readable"><code>readable</code></a> is not feasible. Where possible, using <a href="struct.AsyncFd.html#method.readable"><code>readable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<p>This method takes <code>&amp;mut self</code>, so it is possible to access the inner IO
resource mutably when handling the <a href="struct.AsyncFdReadyMutGuard.html" title="AsyncFdReadyMutGuard"><code>AsyncFdReadyMutGuard</code></a>.</p>
</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/io/async_fd.rs.html#392-403">source</a><h4 class="code-header">pub fn <a href="#method.poll_write_ready" class="fnname">poll_write_ready</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a self,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a>&lt;'a, T&gt;&gt;&gt;</h4></section></summary><div class="docblock"><p>Polls for write readiness.</p>
<p>If the file descriptor is not currently ready for writing, this method
will store a clone of the <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html"><code>Waker</code></a> from the provided <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html"><code>Context</code></a>. When the
file descriptor becomes ready for writing, <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html#method.wake"><code>Waker::wake</code></a> will be called.</p>
<p>Note that on multiple calls to <a href="struct.AsyncFd.html#method.poll_write_ready"><code>poll_write_ready</code></a> or
<a href="struct.AsyncFd.html#method.poll_write_ready_mut"><code>poll_write_ready_mut</code></a>, only the <code>Waker</code> from the <code>Context</code> passed to the
most recent call is scheduled to receive a wakeup. (However,
<a href="struct.AsyncFd.html#method.poll_read_ready"><code>poll_read_ready</code></a> retains a second, independent waker).</p>
<p>This method is intended for cases where creating and pinning a future
via <a href="struct.AsyncFd.html#method.readable"><code>writable</code></a> is not feasible. Where possible, using <a href="struct.AsyncFd.html#method.readable"><code>writable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<p>This method takes <code>&amp;self</code>, so it is possible to call this method
concurrently with other methods on this struct. This method only
provides shared access to the inner IO resource when handling the
<a href="struct.AsyncFdReadyGuard.html" title="AsyncFdReadyGuard"><code>AsyncFdReadyGuard</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.poll_write_ready_mut" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#430-441">source</a><h4 class="code-header">pub fn <a href="#method.poll_write_ready_mut" class="fnname">poll_write_ready_mut</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;<br>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a>&lt;'a, T&gt;&gt;&gt;</h4></section></summary><div class="docblock"><p>Polls for write readiness.</p>
<p>If the file descriptor is not currently ready for writing, this method
will store a clone of the <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html"><code>Waker</code></a> from the provided <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Context.html"><code>Context</code></a>. When the
file descriptor becomes ready for writing, <a href="https://doc.rust-lang.org/nightly/core/task/wake/struct.Waker.html#method.wake"><code>Waker::wake</code></a> will be called.</p>
<p>Note that on multiple calls to <a href="struct.AsyncFd.html#method.poll_write_ready"><code>poll_write_ready</code></a> or
<a href="struct.AsyncFd.html#method.poll_write_ready_mut"><code>poll_write_ready_mut</code></a>, only the <code>Waker</code> from the <code>Context</code> passed to the
most recent call is scheduled to receive a wakeup. (However,
<a href="struct.AsyncFd.html#method.poll_read_ready"><code>poll_read_ready</code></a> retains a second, independent waker).</p>
<p>This method is intended for cases where creating and pinning a future
via <a href="struct.AsyncFd.html#method.readable"><code>writable</code></a> is not feasible. Where possible, using <a href="struct.AsyncFd.html#method.readable"><code>writable</code></a> is
preferred, as this supports polling from multiple tasks at once.</p>
<p>This method takes <code>&amp;mut self</code>, so it is possible to access the inner IO
resource mutably when handling the <a href="struct.AsyncFdReadyMutGuard.html" title="AsyncFdReadyMutGuard"><code>AsyncFdReadyMutGuard</code></a>.</p>
</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/io/async_fd.rs.html#473-475">source</a><h4 class="code-header">pub async fn <a href="#method.readable" class="fnname">readable</a>&lt;'a&gt;(&amp;'a self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a>&lt;'a, T&gt;&gt;</h4></section></summary><div class="docblock"><p>Waits for the file descriptor to become readable, returning a
<a href="struct.AsyncFdReadyGuard.html" title="AsyncFdReadyGuard"><code>AsyncFdReadyGuard</code></a> that must be dropped to resume read-readiness
polling.</p>
<p>This method takes <code>&amp;self</code>, so it is possible to call this method
concurrently with other methods on this struct. This method only
provides shared access to the inner IO resource when handling the
<a href="struct.AsyncFdReadyGuard.html" title="AsyncFdReadyGuard"><code>AsyncFdReadyGuard</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.readable_mut" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#484-486">source</a><h4 class="code-header">pub async fn <a href="#method.readable_mut" class="fnname">readable_mut</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self<br>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a>&lt;'a, T&gt;&gt;</h4></section></summary><div class="docblock"><p>Waits for the file descriptor to become readable, returning a
<a href="struct.AsyncFdReadyMutGuard.html" title="AsyncFdReadyMutGuard"><code>AsyncFdReadyMutGuard</code></a> that must be dropped to resume read-readiness
polling.</p>
<p>This method takes <code>&amp;mut self</code>, so it is possible to access the inner IO
resource mutably when handling the <a href="struct.AsyncFdReadyMutGuard.html" title="AsyncFdReadyMutGuard"><code>AsyncFdReadyMutGuard</code></a>.</p>
</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/io/async_fd.rs.html#497-499">source</a><h4 class="code-header">pub async fn <a href="#method.writable" class="fnname">writable</a>&lt;'a&gt;(&amp;'a self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a>&lt;'a, T&gt;&gt;</h4></section></summary><div class="docblock"><p>Waits for the file descriptor to become writable, returning a
<a href="struct.AsyncFdReadyGuard.html" title="AsyncFdReadyGuard"><code>AsyncFdReadyGuard</code></a> that must be dropped to resume write-readiness
polling.</p>
<p>This method takes <code>&amp;self</code>, so it is possible to call this method
concurrently with other methods on this struct. This method only
provides shared access to the inner IO resource when handling the
<a href="struct.AsyncFdReadyGuard.html" title="AsyncFdReadyGuard"><code>AsyncFdReadyGuard</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.writable_mut" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#508-510">source</a><h4 class="code-header">pub async fn <a href="#method.writable_mut" class="fnname">writable_mut</a>&lt;'a&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self<br>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a>&lt;'a, T&gt;&gt;</h4></section></summary><div class="docblock"><p>Waits for the file descriptor to become writable, returning a
<a href="struct.AsyncFdReadyMutGuard.html" title="AsyncFdReadyMutGuard"><code>AsyncFdReadyMutGuard</code></a> that must be dropped to resume write-readiness
polling.</p>
<p>This method takes <code>&amp;mut self</code>, so it is possible to access the inner IO
resource mutably when handling the <a href="struct.AsyncFdReadyMutGuard.html" title="AsyncFdReadyMutGuard"><code>AsyncFdReadyMutGuard</code></a>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.async_io" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#589-597">source</a><h4 class="code-header">pub async fn <a href="#method.async_io" class="fnname">async_io</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;self,<br>&nbsp;&nbsp;&nbsp;&nbsp;interest: <a class="struct" href="../struct.Interest.html" title="struct tokio::io::Interest">Interest</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;f: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;R&gt;<br>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;R&gt;</h4></section></summary><div class="docblock"><p>Reads or writes from the file descriptor using a user-provided IO operation.</p>
<p>The <code>async_io</code> method is a convenience utility that waits for the file
descriptor to become ready, and then executes the provided IO operation.
Since file descriptors may be marked ready spuriously, the closure will
be called repeatedly until it returns something other than a
<a href="https://doc.rust-lang.org/nightly/std/io/error/enum.ErrorKind.html#variant.WouldBlock"><code>WouldBlock</code></a> error. This is done using the following loop:</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>async_io&lt;R&gt;(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="kw-2">mut </span>f: <span class="kw">impl </span>FnMut(<span class="kw-2">&amp;</span>T) -&gt; io::Result&lt;R&gt;) -&gt; io::Result&lt;R&gt; {
<span class="kw">loop </span>{
<span class="comment">// or `readable` if called with the read interest.
</span><span class="kw">let </span>guard = <span class="self">self</span>.writable().<span class="kw">await</span><span class="question-mark">?</span>;
<span class="kw">match </span>guard.try_io(<span class="kw-2">&amp;mut </span>f) {
<span class="prelude-val">Ok</span>(result) =&gt; <span class="kw">return </span>result,
<span class="prelude-val">Err</span>(_would_block) =&gt; <span class="kw">continue</span>,
}
}
}</code></pre></div>
<p>The closure should only return a <a href="https://doc.rust-lang.org/nightly/std/io/error/enum.ErrorKind.html#variant.WouldBlock"><code>WouldBlock</code></a> error if it has performed
an IO operation on the file descriptor that failed due to the file descriptor not being
ready. Returning a <a href="https://doc.rust-lang.org/nightly/std/io/error/enum.ErrorKind.html#variant.WouldBlock"><code>WouldBlock</code></a> error in any other situation will
incorrectly clear the readiness flag, which can cause the file descriptor to
behave incorrectly.</p>
<p>The closure should not perform the IO operation using any of the methods
defined on the Tokio <a href="struct.AsyncFd.html" title="AsyncFd"><code>AsyncFd</code></a> type, as this will mess with the
readiness flag and can cause the file descriptor 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>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<p>This example sends some bytes on the inner <a href="https://doc.rust-lang.org/nightly/std/net/udp/struct.UdpSocket.html" title="std::net::UdpSocket"><code>std::net::UdpSocket</code></a>. The <code>async_io</code>
method waits for readiness, and retries if the send operation does block. This example
is equivalent to the one given for <a href="struct.AsyncFdReadyGuard.html#method.try_io"><code>try_io</code></a>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{Interest, unix::AsyncFd};
<span class="kw">use </span>std::io;
<span class="kw">use </span>std::net::UdpSocket;
<span class="attribute">#[tokio::main]
</span><span class="kw">async fn </span>main() -&gt; io::Result&lt;()&gt; {
<span class="kw">let </span>socket = UdpSocket::bind(<span class="string">&quot;0.0.0.0:8080&quot;</span>)<span class="question-mark">?</span>;
socket.set_nonblocking(<span class="bool-val">true</span>)<span class="question-mark">?</span>;
<span class="kw">let </span>async_fd = AsyncFd::new(socket)<span class="question-mark">?</span>;
<span class="kw">let </span>written = async_fd
.async_io(Interest::WRITABLE, |inner| inner.send(<span class="kw-2">&amp;</span>[<span class="number">1</span>, <span class="number">2</span>]))
.<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">println!</span>(<span class="string">&quot;wrote {written} bytes&quot;</span>);
<span class="prelude-val">Ok</span>(())
}</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.async_io_mut" class="method has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#605-613">source</a><h4 class="code-header">pub async fn <a href="#method.async_io_mut" class="fnname">async_io_mut</a>&lt;R&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;interest: <a class="struct" href="../struct.Interest.html" title="struct tokio::io::Interest">Interest</a>,<br>&nbsp;&nbsp;&nbsp;&nbsp;f: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/function/trait.FnMut.html" title="trait core::ops::function::FnMut">FnMut</a>(<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;R&gt;<br>) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;R&gt;</h4></section></summary><div class="docblock"><p>Reads or writes from the file descriptor using a user-provided IO operation.</p>
<p>The behavior is the same as <a href="struct.AsyncFd.html#method.async_io"><code>async_io</code></a>, except that the closure can mutate the inner
value of the <a href="struct.AsyncFd.html" title="AsyncFd"><code>AsyncFd</code></a>.</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-AsFd-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#623-627">source</a><a href="#impl-AsFd-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/owned/trait.AsFd.html" title="trait std::os::fd::owned::AsFd">AsFd</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.as_fd" class="method trait-impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#624-626">source</a><a href="#method.as_fd" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/std/os/fd/owned/trait.AsFd.html#tymethod.as_fd" class="fnname">as_fd</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/std/os/fd/owned/struct.BorrowedFd.html" title="struct std::os::fd::owned::BorrowedFd">BorrowedFd</a>&lt;'_&gt;</h4></section></summary><div class='docblock'>Borrows the file descriptor. <a href="https://doc.rust-lang.org/nightly/std/os/fd/owned/trait.AsFd.html#tymethod.as_fd">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-AsRawFd-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#616-620">source</a><a href="#impl-AsRawFd-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;</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/io/async_fd.rs.html#617-619">source</a><a href="#method.as_raw_fd" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd" class="fnname">as_raw_fd</a>(&amp;self) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/type.RawFd.html" title="type std::os::fd::raw::RawFd">RawFd</a></h4></section></summary><div class='docblock'>Extracts the raw file descriptor. <a href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html#tymethod.as_raw_fd">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Debug-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#629-635">source</a><a href="#impl-Debug-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</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/tokio/io/async_fd.rs.html#630-634">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fnname">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Drop-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#637-641">source</a><a href="#impl-Drop-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/os/fd/raw/trait.AsRawFd.html" title="trait std::os::fd::raw::AsRawFd">AsRawFd</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html" title="trait core::ops::drop::Drop">Drop</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</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/tokio/io/async_fd.rs.html#638-640">source</a><a href="#method.drop" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html#tymethod.drop" class="fnname">drop</a>(&amp;mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a href="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html#tymethod.drop">Read more</a></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-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-RefUnwindSafe-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;</h3></section><section id="impl-Send-for-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-Send-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</span></h3></section><section id="impl-Sync-for-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-Sync-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a>,</span></h3></section><section id="impl-Unpin-for-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-Unpin-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h3></section><section id="impl-UnwindSafe-for-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-UnwindSafe-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; !<a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.UnwindSafe.html" title="trait core::panic::unwind_safe::UnwindSafe">UnwindSafe</a> for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a>&lt;T&gt;</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-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#200">source</a><a href="#impl-Any-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html" title="trait core::any::Any">Any</a> for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: 'static + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</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 class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/any.rs.html#201">source</a><a href="#method.type_id" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id" class="fnname">type_id</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/core/any/struct.TypeId.html" title="struct core::any::TypeId">TypeId</a></h4></section></summary><div class='docblock'>Gets the <code>TypeId</code> of <code>self</code>. <a href="https://doc.rust-lang.org/nightly/core/any/trait.Any.html#tymethod.type_id">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-Borrow%3CT%3E-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#211">source</a><a href="#impl-Borrow%3CT%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html" title="trait core::borrow::Borrow">Borrow</a>&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#213">source</a></span><a href="#method.borrow" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow" class="fnname">borrow</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;</a>T</h4></section></summary><div class='docblock'>Immutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-BorrowMut%3CT%3E-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#220">source</a><a href="#impl-BorrowMut%3CT%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html" title="trait core::borrow::BorrowMut">BorrowMut</a>&lt;T&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,</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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/91522" title="Tracking issue for const_borrow">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/borrow.rs.html#221">source</a></span><a href="#method.borrow_mut" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut" class="fnname">borrow_mut</a>(&amp;mut self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&amp;mut </a>T</h4></section></summary><div class='docblock'>Mutably borrows from an owned value. <a href="https://doc.rust-lang.org/nightly/core/borrow/trait.BorrowMut.html#tymethod.borrow_mut">Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-From%3CT%3E-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#733">source</a><a href="#impl-From%3CT%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;T&gt; for T</h3></section></summary><div class="impl-items"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#736">source</a></span><a href="#method.from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from" class="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-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#717">source</a><a href="#impl-Into%3CU%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&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="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#725">source</a></span><a href="#method.into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html#tymethod.into" class="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><a href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="From">From</a>&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-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#775">source</a><a href="#impl-TryFrom%3CU%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&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 href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" class="associatedtype">Error</a> = <a class="enum" href="https://doc.rust-lang.org/nightly/core/convert/enum.Infallible.html" title="enum core::convert::Infallible">Infallible</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#781">source</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#tymethod.try_from" class="fnname">try_from</a>(value: U) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;T, &lt;T as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;U&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details><details class="rustdoc-toggle implementors-toggle"><summary><section id="impl-TryInto%3CU%3E-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#760">source</a><a href="#impl-TryInto%3CU%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl&lt;T, U&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html" title="trait core::convert::TryInto">TryInto</a>&lt;U&gt; for T<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;U: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&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 href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#associatedtype.Error" class="associatedtype">Error</a> = &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a></h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_into" class="method trait-impl has-srclink"><span class="rightside"><span class="since" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span> · <a class="srclink" href="https://doc.rust-lang.org/nightly/src/core/convert/mod.rs.html#766">source</a></span><a href="#method.try_into" class="anchor"></a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/convert/trait.TryInto.html#tymethod.try_into" class="fnname">try_into</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;U, &lt;U as <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html" title="trait core::convert::TryFrom">TryFrom</a>&lt;T&gt;&gt;::<a class="associatedtype" href="https://doc.rust-lang.org/nightly/core/convert/trait.TryFrom.html#associatedtype.Error" title="type core::convert::TryFrom::Error">Error</a>&gt;</h4></section></summary><div class='docblock'>Performs the conversion.</div></details></div></details></div></section></div></main><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>