| <!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">☰</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.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-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<T></a></li><li><a href="#impl-BorrowMut%3CT%3E-for-AsyncFd%3CT%3E">BorrowMut<T></a></li><li><a href="#impl-From%3CT%3E-for-AsyncFd%3CT%3E">From<T></a></li><li><a href="#impl-Into%3CU%3E-for-AsyncFd%3CT%3E">Into<U></a></li><li><a href="#impl-TryFrom%3CU%3E-for-AsyncFd%3CT%3E">TryFrom<U></a></li><li><a href="#impl-TryInto%3CU%3E-for-AsyncFd%3CT%3E">TryInto<U></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#142-145">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><div class="item-decl"><pre class="rust struct"><code>pub struct AsyncFd<T: AsRawFd> { /* 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 [<code>AsRawFd</code>]. 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 |
| [<code>AsRawFd::as_raw_fd</code>] 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 [<code>std::io::ErrorKind::WouldBlock</code>].</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 [<code>std::net::TcpStream</code>] asynchronous using |
| <code>AsyncFd</code>. It implements <code>read</code> as an async fn, and <code>AsyncWrite</code> as a trait |
| to show how to implement both approaches.</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::AsyncWrite; |
| <span class="kw">use </span>tokio::io::unix::AsyncFd; |
| |
| <span class="kw">pub struct </span>AsyncTcpStream { |
| inner: AsyncFd<TcpStream>, |
| } |
| |
| <span class="kw">impl </span>AsyncTcpStream { |
| <span class="kw">pub fn </span>new(tcp: TcpStream) -> io::Result<<span class="self">Self</span>> { |
| 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">&</span><span class="self">self</span>, out: <span class="kw-2">&mut </span>[u8]) -> io::Result<usize> { |
| <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) => <span class="kw">return </span>result, |
| <span class="prelude-val">Err</span>(_would_block) => <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<<span class="kw-2">&mut </span><span class="self">Self</span>>, |
| cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>, |
| buf: <span class="kw-2">&</span>[u8] |
| ) -> Poll<io::Result<usize>> { |
| <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) => <span class="kw">return </span>Poll::Ready(result), |
| <span class="prelude-val">Err</span>(_would_block) => <span class="kw">continue</span>, |
| } |
| } |
| } |
| |
| <span class="kw">fn </span>poll_flush( |
| <span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, |
| cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>, |
| ) -> Poll<io::Result<()>> { |
| <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<<span class="kw-2">&mut </span><span class="self">Self</span>>, |
| cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>, |
| ) -> Poll<io::Result<()>> { |
| <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#171-476">source</a><a href="#impl-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T: AsRawFd> <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T></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#184-189">source</a><h4 class="code-header">pub fn <a href="#method.new" class="fnname">new</a>(inner: T) -> Result<Self><span class="where fmt-newline">where<br> T: AsRawFd,</span></h4></section></summary><div class="docblock"><p>Creates an AsyncFd backed by (and taking ownership of) an object |
| implementing [<code>AsRawFd</code>]. 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#200-205">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>) -> Result<Self><span class="where fmt-newline">where<br> T: AsRawFd,</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#226-228">source</a><h4 class="code-header">pub fn <a href="#method.get_ref" class="fnname">get_ref</a>(&self) -> &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#232-234">source</a><h4 class="code-header">pub fn <a href="#method.get_mut" class="fnname">get_mut</a>(&mut self) -> &mut 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#248-250">source</a><h4 class="code-header">pub fn <a href="#method.into_inner" class="fnname">into_inner</a>(self) -> 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#279-290">source</a><h4 class="code-header">pub fn <a href="#method.poll_read_ready" class="fnname">poll_read_ready</a><'a>(<br> &'a self,<br> cx: &mut Context<'_><br>) -> Poll<Result<<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a><'a, T>>></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="struct@std::task::Waker"><code>Waker</code></a> from the provided <a href="struct@std::task::Context"><code>Context</code></a>. When the |
| file descriptor becomes ready for reading, <a href="method@std::task::Waker::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>&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#317-328">source</a><h4 class="code-header">pub fn <a href="#method.poll_read_ready_mut" class="fnname">poll_read_ready_mut</a><'a>(<br> &'a mut self,<br> cx: &mut Context<'_><br>) -> Poll<Result<<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a><'a, T>>></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="struct@std::task::Waker"><code>Waker</code></a> from the provided <a href="struct@std::task::Context"><code>Context</code></a>. When the |
| file descriptor becomes ready for reading, <a href="method@std::task::Waker::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>&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#357-368">source</a><h4 class="code-header">pub fn <a href="#method.poll_write_ready" class="fnname">poll_write_ready</a><'a>(<br> &'a self,<br> cx: &mut Context<'_><br>) -> Poll<Result<<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a><'a, T>>></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="struct@std::task::Waker"><code>Waker</code></a> from the provided <a href="struct@std::task::Context"><code>Context</code></a>. When the |
| file descriptor becomes ready for writing, <a href="method@std::task::Waker::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>&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#395-406">source</a><h4 class="code-header">pub fn <a href="#method.poll_write_ready_mut" class="fnname">poll_write_ready_mut</a><'a>(<br> &'a mut self,<br> cx: &mut Context<'_><br>) -> Poll<Result<<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a><'a, T>>></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="struct@std::task::Waker"><code>Waker</code></a> from the provided <a href="struct@std::task::Context"><code>Context</code></a>. When the |
| file descriptor becomes ready for writing, <a href="method@std::task::Waker::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>&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#438-440">source</a><h4 class="code-header">pub async fn <a href="#method.readable" class="fnname">readable</a><'a>(&'a self) -> Result<<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a><'a, T>></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>&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#449-451">source</a><h4 class="code-header">pub async fn <a href="#method.readable_mut" class="fnname">readable_mut</a><'a>(<br> &'a mut self<br>) -> Result<<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a><'a, T>></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>&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#462-464">source</a><h4 class="code-header">pub async fn <a href="#method.writable" class="fnname">writable</a><'a>(&'a self) -> Result<<a class="struct" href="struct.AsyncFdReadyGuard.html" title="struct tokio::io::unix::AsyncFdReadyGuard">AsyncFdReadyGuard</a><'a, T>></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>&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#473-475">source</a><h4 class="code-header">pub async fn <a href="#method.writable_mut" class="fnname">writable_mut</a><'a>(<br> &'a mut self<br>) -> Result<<a class="struct" href="struct.AsyncFdReadyMutGuard.html" title="struct tokio::io::unix::AsyncFdReadyMutGuard">AsyncFdReadyMutGuard</a><'a, T>></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>&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></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-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#478-482">source</a><a href="#impl-AsRawFd-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T: AsRawFd> AsRawFd for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T></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#479-481">source</a><a href="#method.as_raw_fd" class="anchor"></a><h4 class="code-header">fn <a class="fnname">as_raw_fd</a>(&self) -> 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-Debug-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#484-490">source</a><a href="#impl-Debug-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T: Debug + AsRawFd> Debug for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T></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#485-489">source</a><a href="#method.fmt" class="anchor"></a><h4 class="code-header">fn <a class="fnname">fmt</a>(&self, f: &mut Formatter<'_>) -> Result</h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a>Read more</a></div></details></div></details><details class="rustdoc-toggle implementors-toggle" open><summary><section id="impl-Drop-for-AsyncFd%3CT%3E" class="impl has-srclink"><a class="srclink rightside" href="../../../src/tokio/io/async_fd.rs.html#492-496">source</a><a href="#impl-Drop-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T: AsRawFd> Drop for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T></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#493-495">source</a><a href="#method.drop" class="anchor"></a><h4 class="code-header">fn <a class="fnname">drop</a>(&mut self)</h4></section></summary><div class='docblock'>Executes the destructor for this type. <a>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<T> !RefUnwindSafe for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T></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<T> Send for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T><span class="where fmt-newline">where<br> T: Send,</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<T> Sync for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T><span class="where fmt-newline">where<br> T: Sync,</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<T> Unpin for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T><span class="where fmt-newline">where<br> T: Unpin,</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<T> !UnwindSafe for <a class="struct" href="struct.AsyncFd.html" title="struct tokio::io::unix::AsyncFd">AsyncFd</a><T></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 href="#impl-Any-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T> Any for T<span class="where fmt-newline">where<br> 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>(&self) -> 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-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-Borrow%3CT%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T> Borrow<T> for T<span class="where fmt-newline">where<br> 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>(&self) -> &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-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-BorrowMut%3CT%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T> BorrowMut<T> for T<span class="where fmt-newline">where<br> 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>(&mut self) -> &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-AsyncFd%3CT%3E" class="impl has-srclink"><a href="#impl-From%3CT%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T> From<T> 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) -> 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 href="#impl-Into%3CU%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T, U> Into<U> for T<span class="where fmt-newline">where<br> U: From<T>,</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) -> 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]<T> 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 href="#impl-TryFrom%3CU%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T, U> TryFrom<U> for T<span class="where fmt-newline">where<br> U: Into<T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error-1" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error-1" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = Infallible</h4></section></summary><div class='docblock'>The type returned in the event of a conversion error.</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.try_from" class="method trait-impl has-srclink"><span class="since rightside" title="const unstable">const: <a href="https://github.com/rust-lang/rust/issues/88674" title="Tracking issue for const_convert">unstable</a></span><a href="#method.try_from" class="anchor"></a><h4 class="code-header">fn <a class="fnname">try_from</a>(value: U) -> Result<T, <T as TryFrom<U>>::Error></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 href="#impl-TryInto%3CU%3E-for-AsyncFd%3CT%3E" class="anchor"></a><h3 class="code-header">impl<T, U> TryInto<U> for T<span class="where fmt-newline">where<br> U: TryFrom<T>,</span></h3></section></summary><div class="impl-items"><details class="rustdoc-toggle" open><summary><section id="associatedtype.Error" class="associatedtype trait-impl has-srclink"><a href="#associatedtype.Error" class="anchor"></a><h4 class="code-header">type <a class="associatedtype">Error</a> = <U as TryFrom<T>>::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) -> Result<U, <U as TryFrom<T>>::Error></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> |