blob: 4283117edd5fe309f552f56042ced5f7e172b776 [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 `AsyncWrite` types."><meta name="keywords" content="rust, rustlang, rust-lang, AsyncWriteExt"><title>AsyncWriteExt 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="#">AsyncWriteExt</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.close">close</a></li><li><a href="#method.flush">flush</a></li><li><a href="#method.into_sink">into_sink</a></li><li><a href="#method.write">write</a></li><li><a href="#method.write_all">write_all</a></li><li><a href="#method.write_vectored">write_vectored</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="#">AsyncWriteExt</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#401">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 AsyncWriteExt: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</a> {
fn <a href="#method.flush" class="fnname">flush</a>(&amp;mut self) -&gt; <a class="struct" href="struct.Flush.html" title="struct futures::io::Flush">Flush</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.Flush.html" title="struct futures::io::Flush">Flush</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.Flush.html" title="struct futures::io::Flush">Flush</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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;(), <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.close" class="fnname">close</a>(&amp;mut self) -&gt; <a class="struct" href="struct.Close.html" title="struct futures::io::Close">Close</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.Close.html" title="struct futures::io::Close">Close</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.Close.html" title="struct futures::io::Close">Close</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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;(), <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.write" class="fnname">write</a>(&amp;'a mut self, buf: &amp;'a [u8]) -&gt; <a class="struct" href="struct.Write.html" title="struct futures::io::Write">Write</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.Write.html" title="struct futures::io::Write">Write</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.Write.html" title="struct futures::io::Write">Write</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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.write_vectored" class="fnname">write_vectored</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;'a [<a class="struct" href="struct.IoSlice.html" title="struct futures::io::IoSlice">IoSlice</a>&lt;'a&gt;]<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="struct" href="struct.WriteVectored.html" title="struct futures::io::WriteVectored">WriteVectored</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.WriteVectored.html" title="struct futures::io::WriteVectored">WriteVectored</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.WriteVectored.html" title="struct futures::io::WriteVectored">WriteVectored</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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.write_all" class="fnname">write_all</a>(&amp;'a mut self, buf: &amp;'a [u8]) -&gt; <a class="struct" href="struct.WriteAll.html" title="struct futures::io::WriteAll">WriteAll</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.WriteAll.html" title="struct futures::io::WriteAll">WriteAll</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.WriteAll.html" title="struct futures::io::WriteAll">WriteAll</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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;(), <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.into_sink" class="fnname">into_sink</a>&lt;Item&gt;(self) -&gt; <a class="struct" href="struct.IntoSink.html" title="struct futures::io::IntoSink">IntoSink</a>&lt;Self, Item&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Item: AsRef&lt;[u8]&gt;</span>,
{ ... }
}</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>AsyncWrite</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.flush" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#424-426">source</a><h4 class="code-header">fn <a href="#method.flush" class="fnname">flush</a>(&amp;mut self) -&gt; <a class="struct" href="struct.Flush.html" title="struct futures::io::Flush">Flush</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.Flush.html" title="struct futures::io::Flush">Flush</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.Flush.html" title="struct futures::io::Flush">Flush</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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;(), <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 entirely flush this <code>AsyncWrite</code>.</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::{AllowStdIo, AsyncWriteExt};
<span class="kw">use </span>std::io::{BufWriter, Cursor};
<span class="kw">let </span><span class="kw-2">mut </span>output = <span class="macro">vec!</span>[<span class="number">0u8</span>; <span class="number">5</span>];
{
<span class="kw">let </span>writer = Cursor::new(<span class="kw-2">&amp;mut </span>output);
<span class="kw">let </span><span class="kw-2">mut </span>buffered = AllowStdIo::new(BufWriter::new(writer));
buffered.write_all(<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>;
buffered.write_all(<span class="kw-2">&amp;</span>[<span class="number">3</span>, <span class="number">4</span>]).<span class="kw">await</span><span class="question-mark">?</span>;
buffered.flush().<span class="kw">await</span><span class="question-mark">?</span>;
}
<span class="macro">assert_eq!</span>(output, [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">0</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.close" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#432-434">source</a><h4 class="code-header">fn <a href="#method.close" class="fnname">close</a>(&amp;mut self) -&gt; <a class="struct" href="struct.Close.html" title="struct futures::io::Close">Close</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.Close.html" title="struct futures::io::Close">Close</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.Close.html" title="struct futures::io::Close">Close</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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;(), <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 entirely close this <code>AsyncWrite</code>.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#443-445">source</a><h4 class="code-header">fn <a href="#method.write" class="fnname">write</a>(&amp;'a mut self, buf: &amp;'a [u8]) -&gt; <a class="struct" href="struct.Write.html" title="struct futures::io::Write">Write</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.Write.html" title="struct futures::io::Write">Write</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.Write.html" title="struct futures::io::Write">Write</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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 write bytes from <code>buf</code> into the object.</p>
<p>The returned future will resolve to the number of bytes written once the write
operation is completed.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_vectored" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#455-457">source</a><h4 class="code-header">fn <a href="#method.write_vectored" class="fnname">write_vectored</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;'a mut self,<br>&nbsp;&nbsp;&nbsp;&nbsp;bufs: &amp;'a [<a class="struct" href="struct.IoSlice.html" title="struct futures::io::IoSlice">IoSlice</a>&lt;'a&gt;]<br>) -&gt; <a class="struct" href="struct.WriteVectored.html" title="struct futures::io::WriteVectored">WriteVectored</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.WriteVectored.html" title="struct futures::io::WriteVectored">WriteVectored</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.WriteVectored.html" title="struct futures::io::WriteVectored">WriteVectored</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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 write bytes from <code>bufs</code> into the object using vectored
IO operations.</p>
<p>The returned future will resolve to the number of bytes written once the write
operation is completed.</p>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_all" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#482-484">source</a><h4 class="code-header">fn <a href="#method.write_all" class="fnname">write_all</a>(&amp;'a mut self, buf: &amp;'a [u8]) -&gt; <a class="struct" href="struct.WriteAll.html" title="struct futures::io::WriteAll">WriteAll</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.WriteAll.html" title="struct futures::io::WriteAll">WriteAll</a>&lt;'_, W&gt;</span><code class="content"><span class="where fmt-newline">impl&lt;W&gt; <a class="trait" href="../future/trait.Future.html" title="trait futures::future::Future">Future</a> for <a class="struct" href="struct.WriteAll.html" title="struct futures::io::WriteAll">WriteAll</a>&lt;'_, W&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</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;(), <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>Write data into this object.</p>
<p>Creates a future that will write the entire contents of the buffer <code>buf</code> into
this <code>AsyncWrite</code>.</p>
<p>The returned future will not complete until all the data has been written.</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::{AsyncWriteExt, Cursor};
<span class="kw">let </span><span class="kw-2">mut </span>writer = Cursor::new(<span class="macro">vec!</span>[<span class="number">0u8</span>; <span class="number">5</span>]);
writer.write_all(<span class="kw-2">&amp;</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>]).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(writer.into_inner(), [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">0</span>]);</code></pre></div>
</div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.into_sink" class="method has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#584-586">source</a><h4 class="code-header">fn <a href="#method.into_sink" class="fnname">into_sink</a>&lt;Item&gt;(self) -&gt; <a class="struct" href="struct.IntoSink.html" title="struct futures::io::IntoSink">IntoSink</a>&lt;Self, Item&gt;<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Item: AsRef&lt;[u8]&gt;,</span></h4></section></summary><div class="docblock"><p>Allow using an <a href="trait.AsyncWrite.html" title="AsyncWrite"><code>AsyncWrite</code></a> as a <a href="../sink/trait.Sink.html"><code>Sink</code></a><code>&lt;Item: AsRef&lt;[u8]&gt;&gt;</code>.</p>
<p>This adapter produces a sink that will write each value passed to it
into the underlying writer.</p>
<p>Note that this function consumes the given writer, returning a wrapped
version.</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::AsyncWriteExt;
<span class="kw">use </span>futures::stream::{<span class="self">self</span>, StreamExt};
<span class="kw">let </span>stream = stream::iter(<span class="macro">vec!</span>[<span class="prelude-val">Ok</span>([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>]), <span class="prelude-val">Ok</span>([<span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>])]);
<span class="kw">let </span><span class="kw-2">mut </span>writer = <span class="macro">vec!</span>[];
stream.forward((<span class="kw-2">&amp;mut </span>writer).into_sink()).<span class="kw">await</span><span class="question-mark">?</span>;
<span class="macro">assert_eq!</span>(writer, <span class="macro">vec!</span>[<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</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-AsyncWriteExt-for-W" class="impl has-srclink"><a class="srclink rightside" href="../../src/futures_util/io/mod.rs.html#592">source</a><a href="#impl-AsyncWriteExt-for-W" class="anchor"></a><h3 class="code-header">impl&lt;W&gt; <a class="trait" href="trait.AsyncWriteExt.html" title="trait futures::io::AsyncWriteExt">AsyncWriteExt</a> for W<span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;W: <a class="trait" href="trait.AsyncWrite.html" title="trait futures::io::AsyncWrite">AsyncWrite</a> + ?Sized,</span></h3></section></div><script src="../../implementors/futures_util/io/trait.AsyncWriteExt.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>