| <!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="Writes bytes to a sink."><meta name="keywords" content="rust, rustlang, rust-lang, AsyncWriteExt"><title>AsyncWriteExt in tokio::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">☰</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="#">AsyncWriteExt</a></h2><div class="sidebar-elems"><section><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.flush">flush</a></li><li><a href="#method.shutdown">shutdown</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_all_buf">write_all_buf</a></li><li><a href="#method.write_buf">write_buf</a></li><li><a href="#method.write_f32">write_f32</a></li><li><a href="#method.write_f32_le">write_f32_le</a></li><li><a href="#method.write_f64">write_f64</a></li><li><a href="#method.write_f64_le">write_f64_le</a></li><li><a href="#method.write_i128">write_i128</a></li><li><a href="#method.write_i128_le">write_i128_le</a></li><li><a href="#method.write_i16">write_i16</a></li><li><a href="#method.write_i16_le">write_i16_le</a></li><li><a href="#method.write_i32">write_i32</a></li><li><a href="#method.write_i32_le">write_i32_le</a></li><li><a href="#method.write_i64">write_i64</a></li><li><a href="#method.write_i64_le">write_i64_le</a></li><li><a href="#method.write_i8">write_i8</a></li><li><a href="#method.write_u128">write_u128</a></li><li><a href="#method.write_u128_le">write_u128_le</a></li><li><a href="#method.write_u16">write_u16</a></li><li><a href="#method.write_u16_le">write_u16_le</a></li><li><a href="#method.write_u32">write_u32</a></li><li><a href="#method.write_u32_le">write_u32_le</a></li><li><a href="#method.write_u64">write_u64</a></li><li><a href="#method.write_u64_le">write_u64_le</a></li><li><a href="#method.write_u8">write_u8</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 tokio::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">tokio</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/tokio/io/util/async_write_ext.rs.html#69-1290">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 trait"><code>pub trait AsyncWriteExt: <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> { |
| <details class="rustdoc-toggle type-contents-toggle"><summary class="hideme"><span>Show 29 methods</span></summary> fn <a href="#method.write" class="fnname">write</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -> Write<'a, Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_vectored" class="fnname">write_vectored</a><'a, 'b>(<br> &'a mut self,<br> bufs: &'a [<a class="struct" href="https://doc.rust-lang.org/nightly/std/io/struct.IoSlice.html" title="struct std::io::IoSlice">IoSlice</a><'b>]<br> ) -> WriteVectored<'a, 'b, Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_buf" class="fnname">write_buf</a><'a, B>(&'a mut self, src: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>B) -> WriteBuf<'a, Self, B><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> B: <a class="trait" href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf">Buf</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_all_buf" class="fnname">write_all_buf</a><'a, B>(<br> &'a mut self,<br> src: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>B<br> ) -> WriteAllBuf<'a, Self, B><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> B: <a class="trait" href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf">Buf</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_all" class="fnname">write_all</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -> WriteAll<'a, Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u8" class="fnname">write_u8</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>) -> WriteU8<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i8" class="fnname">write_i8</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i8.html">i8</a>) -> WriteI8<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u16" class="fnname">write_u16</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u16.html">u16</a>) -> WriteU16<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i16" class="fnname">write_i16</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>) -> WriteI16<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u32" class="fnname">write_u32</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> WriteU32<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i32" class="fnname">write_i32</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -> WriteI32<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u64" class="fnname">write_u64</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> WriteU64<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i64" class="fnname">write_i64</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -> WriteI64<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u128" class="fnname">write_u128</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u128.html">u128</a>) -> WriteU128<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i128" class="fnname">write_i128</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i128.html">i128</a>) -> WriteI128<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_f32" class="fnname">write_f32</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>) -> WriteF32<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_f64" class="fnname">write_f64</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>) -> WriteF64<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u16_le" class="fnname">write_u16_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u16.html">u16</a>) -> WriteU16Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i16_le" class="fnname">write_i16_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>) -> WriteI16Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u32_le" class="fnname">write_u32_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> WriteU32Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i32_le" class="fnname">write_i32_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -> WriteI32Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u64_le" class="fnname">write_u64_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> WriteU64Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i64_le" class="fnname">write_i64_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -> WriteI64Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_u128_le" class="fnname">write_u128_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u128.html">u128</a>) -> WriteU128Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_i128_le" class="fnname">write_i128_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i128.html">i128</a>) -> WriteI128Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_f32_le" class="fnname">write_f32_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>) -> WriteF32Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.write_f64_le" class="fnname">write_f64_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>) -> WriteF64Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.flush" class="fnname">flush</a>(&mut self) -> Flush<'_, Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| <span class="item-spacer"></span> fn <a href="#method.shutdown" class="fnname">shutdown</a>(&mut self) -> Shutdown<'_, Self><br> <span class="where">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span>, |
| { ... } |
| </details>}</code></pre></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Writes bytes to a sink.</p> |
| <p>Implemented as an extension trait, adding utility methods to all |
| <a href="trait.AsyncWrite.html"><code>AsyncWrite</code></a> types. Callers will tend to import this trait instead of |
| <a href="trait.AsyncWrite.html"><code>AsyncWrite</code></a>.</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span>data = <span class="string">b"some bytes"</span>; |
| |
| <span class="kw">let </span><span class="kw-2">mut </span>pos = <span class="number">0</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>buffer = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="kw">while </span>pos < data.len() { |
| <span class="kw">let </span>bytes_written = buffer.write(<span class="kw-2">&</span>data[pos..]).<span class="kw">await</span><span class="question-mark">?</span>; |
| pos += bytes_written; |
| } |
| |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>See <a href="index.html" title="crate::io">module</a> documentation for more details.</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.write" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#123-128">source</a><h4 class="code-header">fn <a href="#method.write" class="fnname">write</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -> Write<'a, Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes a buffer into this writer, returning how many bytes were |
| written.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write(<span class="kw-2">&mut </span><span class="self">self</span>, buf: <span class="kw-2">&</span>[u8]) -> io::Result<usize>;</code></pre></div> |
| <p>This function will attempt to write the entire contents of <code>buf</code>, but |
| the entire write may not succeed, or the write may also generate an |
| error. A call to <code>write</code> represents <em>at most one</em> attempt to write to |
| any wrapped object.</p> |
| <h5 id="return"><a href="#return">Return</a></h5> |
| <p>If the return value is <code>Ok(n)</code> then it must be guaranteed that <code>n <= buf.len()</code>. A return value of <code>0</code> typically means that the |
| underlying object is no longer able to accept bytes and will likely |
| not be able to in the future as well, or that the buffer provided is |
| empty.</p> |
| <h5 id="errors"><a href="#errors">Errors</a></h5> |
| <p>Each call to <code>write</code> may generate an I/O error indicating that the |
| operation could not be completed. If an error is returned then no bytes |
| in the buffer were written to this writer.</p> |
| <p>It is <strong>not</strong> considered an error if the entire buffer could not be |
| written to this writer.</p> |
| <h5 id="cancel-safety"><a href="#cancel-safety">Cancel safety</a></h5> |
| <p>This method is cancellation safe in the sense that if it is used as |
| the event in a <a href="../macro.select.html"><code>tokio::select!</code></a> statement and some |
| other branch completes first, then it is guaranteed that no data was |
| written to 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>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="comment">// Writes some prefix of the byte string, not necessarily all of it. |
| </span>file.write(<span class="string">b"some bytes"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </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/tokio/io/util/async_write_ext.rs.html#171-176">source</a><h4 class="code-header">fn <a href="#method.write_vectored" class="fnname">write_vectored</a><'a, 'b>(<br> &'a mut self,<br> bufs: &'a [<a class="struct" href="https://doc.rust-lang.org/nightly/std/io/struct.IoSlice.html" title="struct std::io::IoSlice">IoSlice</a><'b>]<br>) -> WriteVectored<'a, 'b, Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Like <a href="trait.AsyncWriteExt.html#method.write"><code>write</code></a>, except that it writes from a slice of buffers.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_vectored(<span class="kw-2">&mut </span><span class="self">self</span>, bufs: <span class="kw-2">&</span>[IoSlice<<span class="lifetime">'_</span>>]) -> io::Result<usize>;</code></pre></div> |
| <p>See <a href="trait.AsyncWrite.html#method.poll_write_vectored" title="AsyncWrite::poll_write_vectored"><code>AsyncWrite::poll_write_vectored</code></a> for more details.</p> |
| <h5 id="cancel-safety-1"><a href="#cancel-safety-1">Cancel safety</a></h5> |
| <p>This method is cancellation safe in the sense that if it is used as |
| the event in a <a href="../macro.select.html"><code>tokio::select!</code></a> statement and some |
| other branch completes first, then it is guaranteed that no data was |
| written to this <code>AsyncWrite</code>.</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>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| <span class="kw">use </span>std::io::IoSlice; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="kw">let </span>bufs: <span class="kw-2">&</span>[<span class="kw">_</span>] = <span class="kw-2">&</span>[ |
| IoSlice::new(<span class="string">b"hello"</span>), |
| IoSlice::new(<span class="string">b" "</span>), |
| IoSlice::new(<span class="string">b"world"</span>), |
| ]; |
| |
| file.write_vectored(<span class="kw-2">&</span>bufs).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_buf" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#251-257">source</a><h4 class="code-header">fn <a href="#method.write_buf" class="fnname">write_buf</a><'a, B>(&'a mut self, src: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>B) -> WriteBuf<'a, Self, B><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> B: <a class="trait" href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf">Buf</a>,</span></h4></section></summary><div class="docblock"><p>Writes a buffer into this writer, advancing the buffer’s internal |
| cursor.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_buf<B: Buf>(<span class="kw-2">&mut </span><span class="self">self</span>, buf: <span class="kw-2">&mut </span>B) -> io::Result<usize>;</code></pre></div> |
| <p>This function will attempt to write the entire contents of <code>buf</code>, but |
| the entire write may not succeed, or the write may also generate an |
| error. After the operation completes, the buffer’s |
| internal cursor is advanced by the number of bytes written. A |
| subsequent call to <code>write_buf</code> using the <strong>same</strong> <code>buf</code> value will |
| resume from the point that the first call to <code>write_buf</code> completed. |
| A call to <code>write_buf</code> represents <em>at most one</em> attempt to write to any |
| wrapped object.</p> |
| <h5 id="return-1"><a href="#return-1">Return</a></h5> |
| <p>If the return value is <code>Ok(n)</code> then it must be guaranteed that <code>n <= buf.len()</code>. A return value of <code>0</code> typically means that the |
| underlying object is no longer able to accept bytes and will likely |
| not be able to in the future as well, or that the buffer provided is |
| empty.</p> |
| <h5 id="errors-1"><a href="#errors-1">Errors</a></h5> |
| <p>Each call to <code>write</code> may generate an I/O error indicating that the |
| operation could not be completed. If an error is returned then no bytes |
| in the buffer were written to this writer.</p> |
| <p>It is <strong>not</strong> considered an error if the entire buffer could not be |
| written to this writer.</p> |
| <h5 id="cancel-safety-2"><a href="#cancel-safety-2">Cancel safety</a></h5> |
| <p>This method is cancellation safe in the sense that if it is used as |
| the event in a <a href="../macro.select.html"><code>tokio::select!</code></a> statement and some |
| other branch completes first, then it is guaranteed that no data was |
| written to this <code>AsyncWrite</code>.</p> |
| <h5 id="examples-2"><a href="#examples-2">Examples</a></h5> |
| <p><a href="crate::fs::File"><code>File</code></a> implements <a href="trait.AsyncWrite.html" title="AsyncWrite"><code>AsyncWrite</code></a> and <a href="https://doc.rust-lang.org/nightly/std/io/cursor/struct.Cursor.html"><code>Cursor</code></a><code><&[u8]></code> implements <a href="../../bytes/buf/buf_impl/trait.Buf.html"><code>Buf</code></a>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="kw">use </span>bytes::Buf; |
| <span class="kw">use </span>std::io::Cursor; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>buffer = Cursor::new(<span class="string">b"data to write"</span>); |
| |
| <span class="comment">// Loop until the entire contents of the buffer are written to |
| // the file. |
| </span><span class="kw">while </span>buffer.has_remaining() { |
| <span class="comment">// Writes some prefix of the byte string, not necessarily |
| // all of it. |
| </span>file.write_buf(<span class="kw-2">&mut </span>buffer).<span class="kw">await</span><span class="question-mark">?</span>; |
| } |
| |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_all_buf" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#315-321">source</a><h4 class="code-header">fn <a href="#method.write_all_buf" class="fnname">write_all_buf</a><'a, B>(&'a mut self, src: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>B) -> WriteAllBuf<'a, Self, B><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,<br> B: <a class="trait" href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf">Buf</a>,</span></h4></section></summary><div class="docblock"><p>Attempts to write an entire buffer into this writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_all_buf(<span class="kw-2">&mut </span><span class="self">self</span>, buf: <span class="kw">impl </span>Buf) -> <span class="prelude-ty">Result</span><(), io::Error> { |
| <span class="kw">while </span>buf.has_remaining() { |
| <span class="self">self</span>.write_buf(<span class="kw-2">&mut </span>buf).<span class="kw">await</span><span class="question-mark">?</span>; |
| } |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| <p>This method will continuously call <a href="trait.AsyncWriteExt.html#method.write"><code>write</code></a> until |
| <a href="../../bytes/buf/buf_impl/trait.Buf.html#method.has_remaining"><code>buf.has_remaining()</code></a> returns false. This method will not |
| return until the entire buffer has been successfully written or an error occurs. The |
| first error generated will be returned.</p> |
| <p>The buffer is advanced after each chunk is successfully written. After failure, |
| <code>src.chunk()</code> will return the chunk that failed to write.</p> |
| <h5 id="cancel-safety-3"><a href="#cancel-safety-3">Cancel safety</a></h5> |
| <p>If <code>write_all_buf</code> is used as the event in a |
| <a href="../macro.select.html"><code>tokio::select!</code></a> statement and some other branch |
| completes first, then the data in the provided buffer may have been |
| partially written. However, it is guaranteed that the provided |
| buffer has been <a href="../../bytes/buf/buf_impl/trait.Buf.html#tymethod.advance">advanced</a> by the amount of bytes that have been |
| partially written.</p> |
| <h5 id="examples-3"><a href="#examples-3">Examples</a></h5> |
| <p><a href="crate::fs::File"><code>File</code></a> implements <a href="trait.AsyncWrite.html" title="AsyncWrite"><code>AsyncWrite</code></a> and <a href="https://doc.rust-lang.org/nightly/std/io/cursor/struct.Cursor.html"><code>Cursor</code></a><code><&[u8]></code> implements <a href="../../bytes/buf/buf_impl/trait.Buf.html"><code>Buf</code></a>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="kw">use </span>std::io::Cursor; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>buffer = Cursor::new(<span class="string">b"data to write"</span>); |
| |
| file.write_all_buf(<span class="kw-2">&mut </span>buffer).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </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/tokio/io/util/async_write_ext.rs.html#364-369">source</a><h4 class="code-header">fn <a href="#method.write_all" class="fnname">write_all</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -> WriteAll<'a, Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Attempts to write an entire buffer into this writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_all(<span class="kw-2">&mut </span><span class="self">self</span>, buf: <span class="kw-2">&</span>[u8]) -> io::Result<()>;</code></pre></div> |
| <p>This method will continuously call <a href="trait.AsyncWriteExt.html#method.write"><code>write</code></a> until there is no more data |
| to be written. This method will not return until the entire buffer |
| has been successfully written or such an error occurs. The first |
| error generated from this method will be returned.</p> |
| <h5 id="cancel-safety-4"><a href="#cancel-safety-4">Cancel safety</a></h5> |
| <p>This method is not cancellation safe. If it is used as the event |
| in a <a href="../macro.select.html"><code>tokio::select!</code></a> statement and some other |
| branch completes first, then the provided buffer may have been |
| partially written, but future calls to <code>write_all</code> will start over |
| from the beginning of the buffer.</p> |
| <h5 id="errors-2"><a href="#errors-2">Errors</a></h5> |
| <p>This function will return the first error that <a href="trait.AsyncWriteExt.html#method.write"><code>write</code></a> returns.</p> |
| <h5 id="examples-4"><a href="#examples-4">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>file = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| file.write_all(<span class="string">b"some bytes"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u8" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u8" class="fnname">write_u8</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>) -> WriteU8<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 8-bit integer to the underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u8(<span class="kw-2">&mut </span><span class="self">self</span>, n: u8) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-3"><a href="#errors-3">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-5"><a href="#examples-5">Examples</a></h5> |
| <p>Write unsigned 8 bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u8(<span class="number">2</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u8(<span class="number">5</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x02\x05"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i8" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i8" class="fnname">write_i8</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i8.html">i8</a>) -> WriteI8<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes a signed 8-bit integer to the underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i8(<span class="kw-2">&mut </span><span class="self">self</span>, n: i8) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-4"><a href="#errors-4">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-6"><a href="#examples-6">Examples</a></h5> |
| <p>Write signed 8 bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i8(-<span class="number">2</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i8(<span class="number">126</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\xFE\x7E"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u16" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u16" class="fnname">write_u16</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u16.html">u16</a>) -> WriteU16<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 16-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u16(<span class="kw-2">&mut </span><span class="self">self</span>, n: u16) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-5"><a href="#errors-5">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-7"><a href="#examples-7">Examples</a></h5> |
| <p>Write unsigned 16-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u16(<span class="number">517</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u16(<span class="number">768</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x02\x05\x03\x00"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i16" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i16" class="fnname">write_i16</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>) -> WriteI16<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes a signed 16-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i16(<span class="kw-2">&mut </span><span class="self">self</span>, n: i16) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-6"><a href="#errors-6">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-8"><a href="#examples-8">Examples</a></h5> |
| <p>Write signed 16-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i16(<span class="number">193</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i16(-<span class="number">132</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x00\xc1\xff\x7c"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u32" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u32" class="fnname">write_u32</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> WriteU32<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 32-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u32(<span class="kw-2">&mut </span><span class="self">self</span>, n: u32) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-7"><a href="#errors-7">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-9"><a href="#examples-9">Examples</a></h5> |
| <p>Write unsigned 32-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u32(<span class="number">267</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u32(<span class="number">1205419366</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x00\x00\x01\x0b\x47\xd9\x3d\x66"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i32" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i32" class="fnname">write_i32</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -> WriteI32<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes a signed 32-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i32(<span class="kw-2">&mut </span><span class="self">self</span>, n: i32) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-8"><a href="#errors-8">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-10"><a href="#examples-10">Examples</a></h5> |
| <p>Write signed 32-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i32(<span class="number">267</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i32(<span class="number">1205419366</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x00\x00\x01\x0b\x47\xd9\x3d\x66"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u64" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u64" class="fnname">write_u64</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> WriteU64<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 64-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u64(<span class="kw-2">&mut </span><span class="self">self</span>, n: u64) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-9"><a href="#errors-9">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-11"><a href="#examples-11">Examples</a></h5> |
| <p>Write unsigned 64-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u64(<span class="number">918733457491587</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u64(<span class="number">143</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x00\x03\x43\x95\x4d\x60\x86\x83\x00\x00\x00\x00\x00\x00\x00\x8f"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i64" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i64" class="fnname">write_i64</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -> WriteI64<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an signed 64-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i64(<span class="kw-2">&mut </span><span class="self">self</span>, n: i64) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-10"><a href="#errors-10">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-12"><a href="#examples-12">Examples</a></h5> |
| <p>Write signed 64-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i64(i64::MIN).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i64(i64::MAX).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x80\x00\x00\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u128" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u128" class="fnname">write_u128</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u128.html">u128</a>) -> WriteU128<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 128-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u128(<span class="kw-2">&mut </span><span class="self">self</span>, n: u128) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-11"><a href="#errors-11">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-13"><a href="#examples-13">Examples</a></h5> |
| <p>Write unsigned 128-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u128(<span class="number">16947640962301618749969007319746179</span>).<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">0x00</span>, <span class="number">0x03</span>, <span class="number">0x43</span>, <span class="number">0x95</span>, <span class="number">0x4d</span>, <span class="number">0x60</span>, <span class="number">0x86</span>, <span class="number">0x83</span>, |
| <span class="number">0x00</span>, <span class="number">0x03</span>, <span class="number">0x43</span>, <span class="number">0x95</span>, <span class="number">0x4d</span>, <span class="number">0x60</span>, <span class="number">0x86</span>, <span class="number">0x83 |
| </span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i128" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i128" class="fnname">write_i128</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i128.html">i128</a>) -> WriteI128<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an signed 128-bit integer in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i128(<span class="kw-2">&mut </span><span class="self">self</span>, n: i128) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-12"><a href="#errors-12">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-14"><a href="#examples-14">Examples</a></h5> |
| <p>Write signed 128-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i128(i128::MIN).<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">0x80</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, |
| <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0 |
| </span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_f32" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_f32" class="fnname">write_f32</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>) -> WriteF32<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an 32-bit floating point type in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_f32(<span class="kw-2">&mut </span><span class="self">self</span>, n: f32) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-13"><a href="#errors-13">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-15"><a href="#examples-15">Examples</a></h5> |
| <p>Write 32-bit floating point type to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_f32(f32::MIN).<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">0xff</span>, <span class="number">0x7f</span>, <span class="number">0xff</span>, <span class="number">0xff</span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_f64" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_f64" class="fnname">write_f64</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>) -> WriteF64<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an 64-bit floating point type in big-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_f64(<span class="kw-2">&mut </span><span class="self">self</span>, n: f64) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-14"><a href="#errors-14">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-16"><a href="#examples-16">Examples</a></h5> |
| <p>Write 64-bit floating point type to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_f64(f64::MIN).<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">0xff</span>, <span class="number">0xef</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff |
| </span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u16_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u16_le" class="fnname">write_u16_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u16.html">u16</a>) -> WriteU16Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 16-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u16_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: u16) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-15"><a href="#errors-15">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-17"><a href="#examples-17">Examples</a></h5> |
| <p>Write unsigned 16-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u16_le(<span class="number">517</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u16_le(<span class="number">768</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x05\x02\x00\x03"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i16_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i16_le" class="fnname">write_i16_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a>) -> WriteI16Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes a signed 16-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i16_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: i16) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-16"><a href="#errors-16">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-18"><a href="#examples-18">Examples</a></h5> |
| <p>Write signed 16-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i16_le(<span class="number">193</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i16_le(-<span class="number">132</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\xc1\x00\x7c\xff"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u32_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u32_le" class="fnname">write_u32_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -> WriteU32Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 32-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u32_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: u32) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-17"><a href="#errors-17">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-19"><a href="#examples-19">Examples</a></h5> |
| <p>Write unsigned 32-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u32_le(<span class="number">267</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u32_le(<span class="number">1205419366</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x0b\x01\x00\x00\x66\x3d\xd9\x47"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i32_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i32_le" class="fnname">write_i32_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -> WriteI32Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes a signed 32-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i32_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: i32) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-18"><a href="#errors-18">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-20"><a href="#examples-20">Examples</a></h5> |
| <p>Write signed 32-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i32_le(<span class="number">267</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i32_le(<span class="number">1205419366</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x0b\x01\x00\x00\x66\x3d\xd9\x47"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u64_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u64_le" class="fnname">write_u64_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a>) -> WriteU64Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 64-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u64_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: u64) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-19"><a href="#errors-19">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-21"><a href="#examples-21">Examples</a></h5> |
| <p>Write unsigned 64-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u64_le(<span class="number">918733457491587</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_u64_le(<span class="number">143</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x83\x86\x60\x4d\x95\x43\x03\x00\x8f\x00\x00\x00\x00\x00\x00\x00"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i64_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i64_le" class="fnname">write_i64_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a>) -> WriteI64Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an signed 64-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i64_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: i64) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-20"><a href="#errors-20">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-22"><a href="#examples-22">Examples</a></h5> |
| <p>Write signed 64-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i64_le(i64::MIN).<span class="kw">await</span><span class="question-mark">?</span>; |
| writer.write_i64_le(i64::MAX).<span class="kw">await</span><span class="question-mark">?</span>; |
| |
| <span class="macro">assert_eq!</span>(writer, <span class="string">b"\x00\x00\x00\x00\x00\x00\x00\x80\xff\xff\xff\xff\xff\xff\xff\x7f"</span>); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_u128_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_u128_le" class="fnname">write_u128_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u128.html">u128</a>) -> WriteU128Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an unsigned 128-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_u128_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: u128) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-21"><a href="#errors-21">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-23"><a href="#examples-23">Examples</a></h5> |
| <p>Write unsigned 128-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_u128_le(<span class="number">16947640962301618749969007319746179</span>).<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">0x83</span>, <span class="number">0x86</span>, <span class="number">0x60</span>, <span class="number">0x4d</span>, <span class="number">0x95</span>, <span class="number">0x43</span>, <span class="number">0x03</span>, <span class="number">0x00</span>, |
| <span class="number">0x83</span>, <span class="number">0x86</span>, <span class="number">0x60</span>, <span class="number">0x4d</span>, <span class="number">0x95</span>, <span class="number">0x43</span>, <span class="number">0x03</span>, <span class="number">0x00</span>, |
| ]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_i128_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_i128_le" class="fnname">write_i128_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i128.html">i128</a>) -> WriteI128Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an signed 128-bit integer in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_i128_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: i128) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-22"><a href="#errors-22">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-24"><a href="#examples-24">Examples</a></h5> |
| <p>Write signed 128-bit integers to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_i128_le(i128::MIN).<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">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, |
| <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0x80 |
| </span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_f32_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_f32_le" class="fnname">write_f32_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f32.html">f32</a>) -> WriteF32Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an 32-bit floating point type in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_f32_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: f32) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-23"><a href="#errors-23">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-25"><a href="#examples-25">Examples</a></h5> |
| <p>Write 32-bit floating point type to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_f32_le(f32::MIN).<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">0xff</span>, <span class="number">0xff</span>, <span class="number">0x7f</span>, <span class="number">0xff</span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.write_f64_le" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#371-1213">source</a><h4 class="code-header">fn <a href="#method.write_f64_le" class="fnname">write_f64_le</a><'a>(&'a mut self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.f64.html">f64</a>) -> WriteF64Le<<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.reference.html">&'a mut </a>Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Writes an 64-bit floating point type in little-endian order to the |
| underlying writer.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>write_f64_le(<span class="kw-2">&mut </span><span class="self">self</span>, n: f64) -> io::Result<()>;</code></pre></div> |
| <p>It is recommended to use a buffered writer to avoid excessive |
| syscalls.</p> |
| <h5 id="errors-24"><a href="#errors-24">Errors</a></h5> |
| <p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all"><code>AsyncWriteExt::write_all</code></a>.</p> |
| <h5 id="examples-26"><a href="#examples-26">Examples</a></h5> |
| <p>Write 64-bit floating point type to a <code>AsyncWrite</code>:</p> |
| |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, AsyncWriteExt}; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span><span class="kw-2">mut </span>writer = Vec::new(); |
| |
| writer.write_f64_le(f64::MIN).<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">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xff</span>, <span class="number">0xef</span>, <span class="number">0xff |
| </span>]); |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.flush" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#1245-1250">source</a><h4 class="code-header">fn <a href="#method.flush" class="fnname">flush</a>(&mut self) -> Flush<'_, Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Flushes this output stream, ensuring that all intermediately buffered |
| contents reach their destination.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>flush(<span class="kw-2">&mut </span><span class="self">self</span>) -> io::Result<()>;</code></pre></div> |
| <h5 id="errors-25"><a href="#errors-25">Errors</a></h5> |
| <p>It is considered an error if not all bytes could be written due to |
| I/O errors or EOF being reached.</p> |
| <h5 id="examples-27"><a href="#examples-27">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, BufWriter, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span>f = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>buffer = BufWriter::new(f); |
| |
| buffer.write_all(<span class="string">b"some bytes"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| buffer.flush().<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</span>(()) |
| }</code></pre></div> |
| </div></details><details class="rustdoc-toggle method-toggle" open><summary><section id="method.shutdown" class="method has-srclink"><a class="srclink rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#1284-1289">source</a><h4 class="code-header">fn <a href="#method.shutdown" class="fnname">shutdown</a>(&mut self) -> Shutdown<'_, Self><span class="where fmt-newline">where<br> Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</span></h4></section></summary><div class="docblock"><p>Shuts down the output stream, ensuring that the value can be dropped |
| cleanly.</p> |
| <p>Equivalent to:</p> |
| |
| <div class="example-wrap ignore"><div class='tooltip'>ⓘ</div><pre class="rust rust-example-rendered"><code><span class="kw">async fn </span>shutdown(<span class="kw-2">&mut </span><span class="self">self</span>) -> io::Result<()>;</code></pre></div> |
| <p>Similar to <a href="trait.AsyncWriteExt.html#method.flush"><code>flush</code></a>, all intermediately buffered is written to the |
| underlying stream. Once the operation completes, the caller should |
| no longer attempt to write to the stream. For example, the |
| <code>TcpStream</code> implementation will issue a <code>shutdown(Write)</code> sys call.</p> |
| <h5 id="examples-28"><a href="#examples-28">Examples</a></h5> |
| <div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tokio::io::{<span class="self">self</span>, BufWriter, AsyncWriteExt}; |
| <span class="kw">use </span>tokio::fs::File; |
| |
| <span class="attribute">#[tokio::main] |
| </span><span class="kw">async fn </span>main() -> io::Result<()> { |
| <span class="kw">let </span>f = File::create(<span class="string">"foo.txt"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="kw">let </span><span class="kw-2">mut </span>buffer = BufWriter::new(f); |
| |
| buffer.write_all(<span class="string">b"some bytes"</span>).<span class="kw">await</span><span class="question-mark">?</span>; |
| buffer.shutdown().<span class="kw">await</span><span class="question-mark">?</span>; |
| <span class="prelude-val">Ok</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/tokio/io/util/async_write_ext.rs.html#1293">source</a><a href="#impl-AsyncWriteExt-for-W" class="anchor"></a><h3 class="code-header">impl<W: <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> + ?<a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>> <a class="trait" href="trait.AsyncWriteExt.html" title="trait tokio::io::AsyncWriteExt">AsyncWriteExt</a> for W</h3></section></div><script src="../../implementors/tokio/io/util/async_write_ext/trait.AsyncWriteExt.js" async></script></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> |