Files
phy/futures_io/trait.AsyncBufRead.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

60 lines
20 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Read bytes asynchronously."><title>AsyncBufRead in futures_io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="futures_io" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../futures_io/index.html">futures_<wbr>io</a><span class="version">0.3.31</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Async<wbr>BufRead</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.consume" title="consume">consume</a></li><li><a href="#tymethod.poll_fill_buf" title="poll_fill_buf">poll_fill_buf</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-AsyncBufRead-for-%26%5Bu8%5D" title="&#38;[u8]">&#38;[u8]</a></li><li><a href="#impl-AsyncBufRead-for-%26mut+T" title="&#38;mut T">&#38;mut T</a></li><li><a href="#impl-AsyncBufRead-for-Box%3CT%3E" title="Box&#60;T&#62;">Box&#60;T&#62;</a></li><li><a href="#impl-AsyncBufRead-for-Pin%3CP%3E" title="Pin&#60;P&#62;">Pin&#60;P&#62;</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate futures_<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">futures_io</a></span><h1>Trait <span class="trait">AsyncBufRead</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/futures_io/lib.rs.html#254-301">Source</a> </span></div><pre class="rust item-decl"><code>pub trait AsyncBufRead: <a class="trait" href="trait.AsyncRead.html" title="trait futures_io::AsyncRead">AsyncRead</a> {
// Required methods
fn <a href="#tymethod.poll_fill_buf" class="fn">poll_fill_buf</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/1.84.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]&gt;&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.consume" class="fn">consume</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;, amt: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>);
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Read bytes asynchronously.</p>
<p>This trait is analogous to the <code>std::io::BufRead</code> trait, but integrates
with the asynchronous task system. In particular, the <code>poll_fill_buf</code>
method, unlike <code>BufRead::fill_buf</code>, will automatically queue the current task
for wakeup and return if data is not yet available, rather than blocking
the calling thread.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.poll_fill_buf" class="method"><a class="src rightside" href="../src/futures_io/lib.rs.html#283">Source</a><h4 class="code-header">fn <a href="#tymethod.poll_fill_buf" class="fn">poll_fill_buf</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/1.84.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]&gt;&gt;</h4></section></summary><div class="docblock"><p>Attempt to return the contents of the internal buffer, filling it with more data
from the inner reader if it is empty.</p>
<p>On success, returns <code>Poll::Ready(Ok(buf))</code>.</p>
<p>If no data is available for reading, the method returns
<code>Poll::Pending</code> and arranges for the current task (via
<code>cx.waker().wake_by_ref()</code>) to receive a notification when the object becomes
readable or is closed.</p>
<p>This function is a lower-level call. It needs to be paired with the
<a href="trait.AsyncBufRead.html#tymethod.consume" title="method futures_io::AsyncBufRead::consume"><code>consume</code></a> method to function properly. When calling this
method, none of the contents will be “read” in the sense that later
calling <a href="trait.AsyncRead.html#tymethod.poll_read" title="method futures_io::AsyncRead::poll_read"><code>poll_read</code></a> may return the same contents. As such, <a href="trait.AsyncBufRead.html#tymethod.consume" title="method futures_io::AsyncBufRead::consume"><code>consume</code></a> must
be called with the number of bytes that are consumed from this buffer to
ensure that the bytes are never returned twice.</p>
<p>An empty buffer returned indicates that the stream has reached EOF.</p>
<h5 id="implementation"><a class="doc-anchor" href="#implementation">§</a>Implementation</h5>
<p>This function may not return errors of kind <code>WouldBlock</code> or
<code>Interrupted</code>. Implementations must convert <code>WouldBlock</code> into
<code>Poll::Pending</code> and either internally retry or convert
<code>Interrupted</code> into another error kind.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.consume" class="method"><a class="src rightside" href="../src/futures_io/lib.rs.html#300">Source</a><h4 class="code-header">fn <a href="#tymethod.consume" class="fn">consume</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;, amt: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>)</h4></section></summary><div class="docblock"><p>Tells this buffer that <code>amt</code> bytes have been consumed from the buffer,
so they should no longer be returned in calls to <a href="trait.AsyncRead.html#tymethod.poll_read" title="method futures_io::AsyncRead::poll_read"><code>poll_read</code></a>.</p>
<p>This function is a lower-level call. It needs to be paired with the
<a href="trait.AsyncBufRead.html#tymethod.poll_fill_buf" title="method futures_io::AsyncBufRead::poll_fill_buf"><code>poll_fill_buf</code></a> method to function properly. This function does
not perform any I/O, it simply informs this object that some amount of
its buffer, returned from <a href="trait.AsyncBufRead.html#tymethod.poll_fill_buf" title="method futures_io::AsyncBufRead::poll_fill_buf"><code>poll_fill_buf</code></a>, has been consumed and should
no longer be returned. As such, this function may do odd things if
<a href="trait.AsyncBufRead.html#tymethod.poll_fill_buf" title="method futures_io::AsyncBufRead::poll_fill_buf"><code>poll_fill_buf</code></a> isnt called before calling it.</p>
<p>The <code>amt</code> must be <code>&lt;=</code> the number of bytes in the buffer returned by
<a href="trait.AsyncBufRead.html#tymethod.poll_fill_buf" title="method futures_io::AsyncBufRead::poll_fill_buf"><code>poll_fill_buf</code></a>.</p>
</div></details></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-AsyncBufRead-for-%26%5Bu8%5D" class="impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#555-557">Source</a><a href="#impl-AsyncBufRead-for-%26%5Bu8%5D" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a> for &amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]</h3></section></summary><div class="impl-items"><section id="method.poll_fill_buf" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#556">Source</a><a href="#method.poll_fill_buf" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.poll_fill_buf" class="fn">poll_fill_buf</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;,
_: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/1.84.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]&gt;&gt;</h4></section><section id="method.consume" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#556">Source</a><a href="#method.consume" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.consume" class="fn">consume</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;, amt: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-AsyncBufRead-for-Pin%3CP%3E" class="impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#529-541">Source</a><a href="#impl-AsyncBufRead-for-Pin%3CP%3E" class="anchor">§</a><h3 class="code-header">impl&lt;P&gt; <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;P&gt;<div class="where">where
P: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/deref/trait.DerefMut.html" title="trait core::ops::deref::DerefMut">DerefMut</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,
P::<a class="associatedtype" href="https://doc.rust-lang.org/1.84.0/core/ops/deref/trait.Deref.html#associatedtype.Target" title="type core::ops::deref::Deref::Target">Target</a>: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a>,</div></h3></section></summary><div class="impl-items"><section id="method.poll_fill_buf-1" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#534-536">Source</a><a href="#method.poll_fill_buf-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.poll_fill_buf" class="fn">poll_fill_buf</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/1.84.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]&gt;&gt;</h4></section><section id="method.consume-1" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#538-540">Source</a><a href="#method.consume-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.consume" class="fn">consume</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;, amt: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-AsyncBufRead-for-%26mut+T" class="impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#525-527">Source</a><a href="#impl-AsyncBufRead-for-%26mut+T" class="anchor">§</a><h3 class="code-header">impl&lt;T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>&gt; <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a> for <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;mut T</a></h3></section></summary><div class="impl-items"><section id="method.poll_fill_buf-2" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#526">Source</a><a href="#method.poll_fill_buf-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.poll_fill_buf" class="fn">poll_fill_buf</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/1.84.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]&gt;&gt;</h4></section><section id="method.consume-2" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#526">Source</a><a href="#method.consume-2" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.consume" class="fn">consume</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;, amt: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>)</h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-AsyncBufRead-for-Box%3CT%3E" class="impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#521-523">Source</a><a href="#impl-AsyncBufRead-for-Box%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: ?<a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a> + <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>&gt; <a class="trait" href="trait.AsyncBufRead.html" title="trait futures_io::AsyncBufRead">AsyncBufRead</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><section id="method.poll_fill_buf-3" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#522">Source</a><a href="#method.poll_fill_buf-3" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.poll_fill_buf" class="fn">poll_fill_buf</a>(
self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;,
cx: &amp;mut <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/task/wake/struct.Context.html" title="struct core::task::wake::Context">Context</a>&lt;'_&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/task/poll/enum.Poll.html" title="enum core::task::poll::Poll">Poll</a>&lt;<a class="type" href="https://doc.rust-lang.org/1.84.0/std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;&amp;[<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.u8.html">u8</a>]&gt;&gt;</h4></section><section id="method.consume-3" class="method trait-impl"><a class="src rightside" href="../src/futures_io/lib.rs.html#522">Source</a><a href="#method.consume-3" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.consume" class="fn">consume</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/pin/struct.Pin.html" title="struct core::pin::Pin">Pin</a>&lt;&amp;mut Self&gt;, amt: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>)</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/futures_io/if_std/trait.AsyncBufRead.js" data-ignore-extern-crates="alloc,core,std" async></script></section></div></main></body></html>