blob: a460f1698362da91e395c29dbb05287d2d489e9c [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="An extension trait which adds utility methods to `AsyncBufRead` types."><meta name="keywords" content="rust, rustlang, rust-lang, AsyncBufReadExt"><title>AsyncBufReadExt in futures::io - 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 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">&#9776;</button><a class="sidebar-logo" href="../../futures/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="../../futures/index.html"><div class="logo-container"><img class="rust-logo" src="../../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">AsyncBufReadExt</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.consume_unpin">consume_unpin</a></li><li><a href="#method.fill_buf">fill_buf</a></li><li><a href="#method.lines">lines</a></li><li><a href="#method.read_line">read_line</a></li><li><a href="#method.read_until">read_until</a></li></ul><h3><a href="#implementors">Implementors</a></h3></section><h2><a href="index.html">In futures::io</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">Trait <a href="../index.html">futures</a>::<wbr><a href="index.html">io</a>::<wbr><a class="trait" href="#">AsyncBufReadExt</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/futures_util/io/mod.rs.html#623">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 trait"><code>pub trait AsyncBufReadExt: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> {
fn <a href="#method.fill_buf" class="fnname">fill_buf</a>(&amp;mut self) -&gt; <a class="struct" href="struct.FillBuf.html" title="struct futures::io::FillBuf">FillBuf</a>&lt;'_, Self&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.FillBuf.html" title="struct futures::io::FillBuf">FillBuf</a>&lt;'a, R&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;'a, R&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.FillBuf.html" title="struct futures::io::FillBuf">FillBuf</a>&lt;'a, R&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + Unpin + ?Sized,</span></span><span class="where fmt-newline"> type <a href="../future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result&lt;&amp;'a [u8], <a class="struct" href="struct.Error.html" title="struct futures::io::Error">Error</a>&gt;;</span></code></span></span></span></span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin</span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.consume_unpin" class="fnname">consume_unpin</a>(&amp;mut self, amt: usize)<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin</span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.read_until" class="fnname">read_until</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte: u8,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;'a mut Vec&lt;u8, Global&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="struct" href="struct.ReadUntil.html" title="struct futures::io::ReadUntil">ReadUntil</a>&lt;'a, Self&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.ReadUntil.html" title="struct futures::io::ReadUntil">ReadUntil</a>&lt;'_, R&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;R&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.ReadUntil.html" title="struct futures::io::ReadUntil">ReadUntil</a>&lt;'_, R&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + Unpin + ?Sized,</span></span><span class="where fmt-newline"> type <a href="../future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result&lt;usize, <a class="struct" href="struct.Error.html" title="struct futures::io::Error">Error</a>&gt;;</span></code></span></span></span></span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin</span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.read_line" class="fnname">read_line</a>(&amp;'a mut self, buf: &amp;'a mut String) -&gt; <a class="struct" href="struct.ReadLine.html" title="struct futures::io::ReadLine">ReadLine</a>&lt;'a, Self&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.ReadLine.html" title="struct futures::io::ReadLine">ReadLine</a>&lt;'_, R&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;R&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.ReadLine.html" title="struct futures::io::ReadLine">ReadLine</a>&lt;'_, R&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + Unpin + ?Sized,</span></span><span class="where fmt-newline"> type <a href="../future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result&lt;usize, <a class="struct" href="struct.Error.html" title="struct futures::io::Error">Error</a>&gt;;</span></code></span></span></span></span><br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin</span>,
{ ... }
<span class="item-spacer"></span> fn <a href="#method.lines" class="fnname">lines</a>(self) -&gt; <a class="struct" href="struct.Lines.html" title="struct futures::io::Lines">Lines</a>&lt;Self&gt; { ... }
}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>An extension trait which adds utility methods to <code>AsyncBufRead</code> types.</p>
</div></details><h2 id="provided-methods" class="small-section-header">Provided Methods<a href="#provided-methods" class="anchor"></a></h2><div class="methods"><details class="rustdoc-toggle method-toggle" open><summary><section id="method.fill_buf" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#647-649">source</a><h4 class="code-header">fn <a href="#method.fill_buf" class="fnname">fill_buf</a>(&amp;mut self) -&gt; <a class="struct" href="struct.FillBuf.html" title="struct futures::io::FillBuf">FillBuf</a>&lt;'_, Self&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.FillBuf.html" title="struct futures::io::FillBuf">FillBuf</a>&lt;'a, R&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;'a, R&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.FillBuf.html" title="struct futures::io::FillBuf">FillBuf</a>&lt;'a, R&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + Unpin + ?Sized,</span></span><span class="where fmt-newline"> type <a href="../future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result&lt;&amp;'a [u8], <a class="struct" href="struct.Error.html" title="struct futures::io::Error">Error</a>&gt;;</span></code></span></span></span></span><span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin,</span></h4></section></summary><div class="docblock"><p>Creates a future which will wait for a non-empty buffer to be available from this I/O
object or EOF to be reached.</p>
<p>This method is the async equivalent to <a href="std::io::BufRead::fill_buf"><code>BufRead::fill_buf</code></a>.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::{io::AsyncBufReadExt <span class="kw">as _</span>, stream::{iter, TryStreamExt <span class="kw">as _</span>}};
<span class="kw">let </span><span class="kw-2">mut </span>stream = iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]), <span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>])]).into_async_read();
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
stream.consume_unpin(<span class="number">2</span>);
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[<span class="number">3</span>]);
stream.consume_unpin(<span class="number">1</span>);
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>]);
stream.consume_unpin(<span class="number">3</span>);
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.consume_unpin" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#671-673">source</a><h4 class="code-header">fn <a href="#method.consume_unpin" class="fnname">consume_unpin</a>(&amp;mut self, amt: usize)<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin,</span></h4></section></summary><div class="docblock"><p>A convenience for calling <a href="trait.AsyncBufRead.html#tymethod.consume" title="AsyncBufRead::consume"><code>AsyncBufRead::consume</code></a> on [<code>Unpin</code>] IO types.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::{io::AsyncBufReadExt <span class="kw">as _</span>, stream::{iter, TryStreamExt <span class="kw">as _</span>}};
<span class="kw">let </span><span class="kw-2">mut </span>stream = iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>(<span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>])]).into_async_read();
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]);
stream.consume_unpin(<span class="number">2</span>);
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[<span class="number">3</span>]);
stream.consume_unpin(<span class="number">1</span>);
<span class="macro">assert_eq!</span>(stream.fill_buf().<span class="kw">await</span><span class="question-mark">?</span>, <span class="macro">vec!</span>[]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.read_until" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#719-721">source</a><h4 class="code-header">fn <a href="#method.read_until" class="fnname">read_until</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;byte: u8,<br>&nbsp;&nbsp;&nbsp;&nbsp;buf: &amp;'a mut Vec&lt;u8, Global&gt;<br>) -&gt; <a class="struct" href="struct.ReadUntil.html" title="struct futures::io::ReadUntil">ReadUntil</a>&lt;'a, Self&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.ReadUntil.html" title="struct futures::io::ReadUntil">ReadUntil</a>&lt;'_, R&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;R&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.ReadUntil.html" title="struct futures::io::ReadUntil">ReadUntil</a>&lt;'_, R&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + Unpin + ?Sized,</span></span><span class="where fmt-newline"> type <a href="../future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result&lt;usize, <a class="struct" href="struct.Error.html" title="struct futures::io::Error">Error</a>&gt;;</span></code></span></span></span></span><span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin,</span></h4></section></summary><div class="docblock"><p>Creates a future which will read all the bytes associated with this I/O
object into <code>buf</code> until the delimiter <code>byte</code> or EOF is reached.
This method is the async equivalent to <a href="std::io::BufRead::read_until"><code>BufRead::read_until</code></a>.</p>
<p>This function will read bytes from the underlying stream until the
delimiter or EOF is found. Once found, all bytes up to, and including,
the delimiter (if found) will be appended to <code>buf</code>.</p>
<p>The returned future will resolve to the number of bytes read once the read
operation is completed.</p>
<p>In the case of an error the buffer and the object will be discarded, with
the error yielded.</p>
<h5 id="examples"><a href="#examples">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::io::{AsyncBufReadExt, Cursor};
<span class="kw">let </span><span class="kw-2">mut </span>cursor = Cursor::new(<span class="string">b&quot;lorem-ipsum&quot;</span>);
<span class="kw">let </span><span class="kw-2">mut </span>buf = <span class="macro">vec!</span>[];
<span class="comment">// cursor is at &#39;l&#39;
</span><span class="kw">let </span>num_bytes = cursor.read_until(<span class="string">b&#39;-&#39;</span>, <span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">6</span>);
<span class="macro">assert_eq!</span>(buf, <span class="string">b&quot;lorem-&quot;</span>);
buf.clear();
<span class="comment">// cursor is at &#39;i&#39;
</span><span class="kw">let </span>num_bytes = cursor.read_until(<span class="string">b&#39;-&#39;</span>, <span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">5</span>);
<span class="macro">assert_eq!</span>(buf, <span class="string">b&quot;ipsum&quot;</span>);
buf.clear();
<span class="comment">// cursor is at EOF
</span><span class="kw">let </span>num_bytes = cursor.read_until(<span class="string">b&#39;-&#39;</span>, <span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">0</span>);
<span class="macro">assert_eq!</span>(buf, <span class="string">b&quot;&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.read_line" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#777-779">source</a><h4 class="code-header">fn <a href="#method.read_line" class="fnname">read_line</a>(&amp;'a mut self, buf: &amp;'a mut String) -&gt; <a class="struct" href="struct.ReadLine.html" title="struct futures::io::ReadLine">ReadLine</a>&lt;'a, Self&gt;<span class="notable-traits"><span class="notable-traits-tooltip"><span class="notable-traits-tooltiptext"><span class="docblock"><span class="notable">Notable traits for <a class="struct" href="struct.ReadLine.html" title="struct futures::io::ReadLine">ReadLine</a>&lt;'_, R&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;R&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.ReadLine.html" title="struct futures::io::ReadLine">ReadLine</a>&lt;'_, R&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + Unpin + ?Sized,</span></span><span class="where fmt-newline"> type <a href="../future/trait.Future.html#associatedtype.Output" class="associatedtype">Output</a> = Result&lt;usize, <a class="struct" href="struct.Error.html" title="struct futures::io::Error">Error</a>&gt;;</span></code></span></span></span></span><span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: Unpin,</span></h4></section></summary><div class="docblock"><p>Creates a future which will read all the bytes associated with this I/O
object into <code>buf</code> until a newline (the 0xA byte) or EOF is reached,
This method is the async equivalent to <a href="std::io::BufRead::read_line"><code>BufRead::read_line</code></a>.</p>
<p>This function will read bytes from the underlying stream until the
newline delimiter (the 0xA byte) or EOF is found. Once found, all bytes
up to, and including, the delimiter (if found) will be appended to
<code>buf</code>.</p>
<p>The returned future will resolve to the number of bytes read once the read
operation is completed.</p>
<p>In the case of an error the buffer and the object will be discarded, with
the error yielded.</p>
<h5 id="errors"><a href="#errors">Errors</a></h5>
<p>This function has the same error semantics as <a href="trait.AsyncBufReadExt.html#method.read_until"><code>read_until</code></a> and will
also return an error if the read bytes are not valid UTF-8. If an I/O
error is encountered then <code>buf</code> may contain some bytes already read in
the event that all data read so far was valid UTF-8.</p>
<h5 id="examples-1"><a href="#examples-1">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::io::{AsyncBufReadExt, Cursor};
<span class="kw">let </span><span class="kw-2">mut </span>cursor = Cursor::new(<span class="string">b&quot;foo\nbar&quot;</span>);
<span class="kw">let </span><span class="kw-2">mut </span>buf = String::new();
<span class="comment">// cursor is at &#39;f&#39;
</span><span class="kw">let </span>num_bytes = cursor.read_line(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">4</span>);
<span class="macro">assert_eq!</span>(buf, <span class="string">&quot;foo\n&quot;</span>);
buf.clear();
<span class="comment">// cursor is at &#39;b&#39;
</span><span class="kw">let </span>num_bytes = cursor.read_line(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">3</span>);
<span class="macro">assert_eq!</span>(buf, <span class="string">&quot;bar&quot;</span>);
buf.clear();
<span class="comment">// cursor is at EOF
</span><span class="kw">let </span>num_bytes = cursor.read_line(<span class="kw-2">&amp;mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(num_bytes, <span class="number">0</span>);
<span class="macro">assert_eq!</span>(buf, <span class="string">&quot;&quot;</span>);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.lines" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#816-818">source</a><h4 class="code-header">fn <a href="#method.lines" class="fnname">lines</a>(self) -&gt; <a class="struct" href="struct.Lines.html" title="struct futures::io::Lines">Lines</a>&lt;Self&gt;</h4></section></summary><div class="docblock"><p>Returns a stream over the lines of this reader.
This method is the async equivalent to <a href="std::io::BufRead::lines"><code>BufRead::lines</code></a>.</p>
<p>The stream returned from this function will yield instances of
<a href="type.Result.html"><code>io::Result</code></a><code>&lt;</code><a href="String"><code>String</code></a><code>&gt;</code>. Each string returned will <em>not</em> have a newline
byte (the 0xA byte) or CRLF (0xD, 0xA bytes) at the end.</p>
<h5 id="errors-1"><a href="#errors-1">Errors</a></h5>
<p>Each line of the stream has the same error semantics as <a href="trait.AsyncBufReadExt.html#method.read_line"><code>AsyncBufReadExt::read_line</code></a>.</p>
<h5 id="examples-2"><a href="#examples-2">Examples</a></h5>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>futures::io::{AsyncBufReadExt, Cursor};
<span class="kw">use </span>futures::stream::StreamExt;
<span class="kw">let </span>cursor = Cursor::new(<span class="string">b&quot;lorem\nipsum\r\ndolor&quot;</span>);
<span class="kw">let </span><span class="kw-2">mut </span>lines_stream = cursor.lines().map(|l| l.unwrap());
<span class="macro">assert_eq!</span>(lines_stream.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(String::from(<span class="string">&quot;lorem&quot;</span>)));
<span class="macro">assert_eq!</span>(lines_stream.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(String::from(<span class="string">&quot;ipsum&quot;</span>)));
<span class="macro">assert_eq!</span>(lines_stream.next().<span class="kw">await</span>, <span class="prelude-val">Some</span>(String::from(<span class="string">&quot;dolor&quot;</span>)));
<span class="macro">assert_eq!</span>(lines_stream.next().<span class="kw">await</span>, <span class="prelude-val">None</span>);</code></pre></div>
</div></details></div><h2 id="implementors" class="small-section-header">Implementors<a href="#implementors" class="anchor"></a></h2><div id="implementors-list"><section id="impl-AsyncBufReadExt-for-R" class="impl has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#824">source</a><a href="#impl-AsyncBufReadExt-for-R" class="anchor"></a><h3 class="code-header">impl&lt;R&gt; <a class="trait" href="trait.AsyncBufReadExt.html" title="trait futures::io::AsyncBufReadExt">AsyncBufReadExt</a> for R<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;R: <a class="trait" href="trait.AsyncBufRead.html" title="trait futures::io::AsyncBufRead">AsyncBufRead</a> + ?Sized,</span></h3></section></div><script src="../../implementors/futures_util/io/trait.AsyncBufReadExt.js" async></script></section></div></main><div id="rustdoc-vars" data-root-path="../../" data-current-crate="futures" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>