806 lines
94 KiB
HTML
806 lines
94 KiB
HTML
<!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."><title>AsyncWriteExt in tokio::io - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="tokio" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11) (Arch Linux rust 1:1.93.1-1)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">AsyncWriteExt</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../tokio/index.html">tokio</a><span class="version">1.49.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Async<wbr>Write<wbr>Ext</a></h2><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.flush" title="flush">flush</a></li><li><a href="#method.shutdown" title="shutdown">shutdown</a></li><li><a href="#method.write" title="write">write</a></li><li><a href="#method.write_all" title="write_all">write_all</a></li><li><a href="#method.write_all_buf" title="write_all_buf">write_all_buf</a></li><li><a href="#method.write_buf" title="write_buf">write_buf</a></li><li><a href="#method.write_f32" title="write_f32">write_f32</a></li><li><a href="#method.write_f64" title="write_f64">write_f64</a></li><li><a href="#method.write_f32_le" title="write_f32_le">write_f32_le</a></li><li><a href="#method.write_f64_le" title="write_f64_le">write_f64_le</a></li><li><a href="#method.write_i8" title="write_i8">write_i8</a></li><li><a href="#method.write_i16" title="write_i16">write_i16</a></li><li><a href="#method.write_i32" title="write_i32">write_i32</a></li><li><a href="#method.write_i64" title="write_i64">write_i64</a></li><li><a href="#method.write_i16_le" title="write_i16_le">write_i16_le</a></li><li><a href="#method.write_i32_le" title="write_i32_le">write_i32_le</a></li><li><a href="#method.write_i64_le" title="write_i64_le">write_i64_le</a></li><li><a href="#method.write_i128" title="write_i128">write_i128</a></li><li><a href="#method.write_i128_le" title="write_i128_le">write_i128_le</a></li><li><a href="#method.write_u8" title="write_u8">write_u8</a></li><li><a href="#method.write_u16" title="write_u16">write_u16</a></li><li><a href="#method.write_u32" title="write_u32">write_u32</a></li><li><a href="#method.write_u64" title="write_u64">write_u64</a></li><li><a href="#method.write_u16_le" title="write_u16_le">write_u16_le</a></li><li><a href="#method.write_u32_le" title="write_u32_le">write_u32_le</a></li><li><a href="#method.write_u64_le" title="write_u64_le">write_u64_le</a></li><li><a href="#method.write_u128" title="write_u128">write_u128</a></li><li><a href="#method.write_u128_le" title="write_u128_le">write_u128_le</a></li><li><a href="#method.write_vectored" title="write_vectored">write_vectored</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2><a href="index.html">In tokio::<wbr>io</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">tokio</a>::<wbr><a href="index.html">io</a></div><h1>Trait <span class="trait">Async<wbr>Write<wbr>Ext</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/tokio/io/util/async_write_ext.rs.html#72-1329">Source</a> </span></div><pre class="rust item-decl"><code>pub trait AsyncWriteExt: <a class="trait" href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite">AsyncWrite</a> {
|
||
<details class="toggle type-contents-toggle"><summary class="hideme"><span>Show 29 methods</span></summary> // Provided methods
|
||
fn <a href="#method.write" class="fn">write</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>]) -> Write<'a, Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_vectored</a><'a, 'b>(
|
||
&'a mut self,
|
||
bufs: &'a [<a class="struct" href="https://doc.rust-lang.org/1.93.1/std/io/struct.IoSlice.html" title="struct std::io::IoSlice">IoSlice</a><'b>],
|
||
) -> WriteVectored<'a, 'b, Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_buf</a><'a, B>(&'a mut self, src: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&'a mut B</a>) -> WriteBuf<'a, Self, B>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,
|
||
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="fn">write_all_buf</a><'a, B>(
|
||
&'a mut self,
|
||
src: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&'a mut B</a>,
|
||
) -> WriteAllBuf<'a, Self, B>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,
|
||
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="fn">write_all</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>]) -> WriteAll<'a, Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u8</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>) -> WriteU8<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i8</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i8.html">i8</a>) -> WriteI8<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u16</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u16.html">u16</a>) -> WriteU16<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i16</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i16.html">i16</a>) -> WriteI16<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u32</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -> WriteU32<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i32</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i32.html">i32</a>) -> WriteI32<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u64</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u64.html">u64</a>) -> WriteU64<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i64</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i64.html">i64</a>) -> WriteI64<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u128</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u128.html">u128</a>) -> WriteU128<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i128</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i128.html">i128</a>) -> WriteI128<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_f32</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f32.html">f32</a>) -> WriteF32<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_f64</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f64.html">f64</a>) -> WriteF64<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u16_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u16.html">u16</a>) -> WriteU16Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i16_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i16.html">i16</a>) -> WriteI16Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u32_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -> WriteU32Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i32_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i32.html">i32</a>) -> WriteI32Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u64_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u64.html">u64</a>) -> WriteU64Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i64_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i64.html">i64</a>) -> WriteI64Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_u128_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u128.html">u128</a>) -> WriteU128Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_i128_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i128.html">i128</a>) -> WriteI128Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_f32_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f32.html">f32</a>) -> WriteF32Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/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="fn">write_f64_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f64.html">f64</a>) -> WriteF64Le<&mut Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.flush" class="fn">flush</a>(&mut self) -> Flush<'_, Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.shutdown" class="fn">shutdown</a>(&mut self) -> Shutdown<'_, Self>
|
||
<span class="where">where Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a></span> { ... }
|
||
</details>}</code></pre><details class="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" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a> types. Callers will tend to import this trait instead of
|
||
<a href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><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="attr">#[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="mod tokio::io">module</a> documentation for more details.</p>
|
||
</div></details><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.write" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#130-135">Source</a><h4 class="code-header">fn <a href="#method.write" class="fn">write</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>]) -> Write<'a, Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#return">§</a>Return</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 class="doc-anchor" href="#errors">§</a>Errors</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 class="doc-anchor" href="#cancel-safety">§</a>Cancel safety</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" title="macro tokio::select"><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 class="doc-anchor" href="#examples">§</a>Examples</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="attr">#[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>;
|
||
file.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_vectored" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#182-187">Source</a><h4 class="code-header">fn <a href="#method.write_vectored" class="fn">write_vectored</a><'a, 'b>(
|
||
&'a mut self,
|
||
bufs: &'a [<a class="struct" href="https://doc.rust-lang.org/1.93.1/std/io/struct.IoSlice.html" title="struct std::io::IoSlice">IoSlice</a><'b>],
|
||
) -> WriteVectored<'a, 'b, Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></h4></section></summary><div class="docblock"><p>Like <a href="trait.AsyncWriteExt.html#method.write" title="method tokio::io::AsyncWriteExt::write"><code>write</code></a>, except that it writes from a slice of buffers.</p>
|
||
<p>Equivalent to:</p>
|
||
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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="method tokio::io::AsyncWrite::poll_write_vectored"><code>AsyncWrite::poll_write_vectored</code></a> for more details.</p>
|
||
<h5 id="cancel-safety-1"><a class="doc-anchor" href="#cancel-safety-1">§</a>Cancel safety</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" title="macro tokio::select"><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 class="doc-anchor" href="#examples-1">§</a>Examples</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="attr">#[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>;
|
||
file.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_buf" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#266-272">Source</a><h4 class="code-header">fn <a href="#method.write_buf" class="fn">write_buf</a><'a, B>(&'a mut self, src: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&'a mut B</a>) -> WriteBuf<'a, Self, B><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,
|
||
B: <a class="trait" href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf">Buf</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#return-1">§</a>Return</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 class="doc-anchor" href="#errors-1">§</a>Errors</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 class="doc-anchor" href="#cancel-safety-2">§</a>Cancel safety</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" title="macro tokio::select"><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 class="doc-anchor" href="#examples-2">§</a>Examples</h5>
|
||
<p><a href="../fs/struct.File.html" title="struct tokio::fs::File"><code>File</code></a> implements <a href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a> and <a href="https://doc.rust-lang.org/1.93.1/std/io/cursor/struct.Cursor.html" title="struct std::io::cursor::Cursor"><code>Cursor</code></a><code><&[u8]></code> implements <a href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf"><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="attr">#[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>;
|
||
}
|
||
file.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_all_buf" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#334-340">Source</a><h4 class="code-header">fn <a href="#method.write_all_buf" class="fn">write_all_buf</a><'a, B>(
|
||
&'a mut self,
|
||
src: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.reference.html">&'a mut B</a>,
|
||
) -> WriteAllBuf<'a, Self, B><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,
|
||
B: <a class="trait" href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf">Buf</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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" title="method tokio::io::AsyncWriteExt::write"><code>write</code></a> until
|
||
<a href="../../bytes/buf/buf_impl/trait.Buf.html#method.has_remaining" title="method bytes::buf::buf_impl::Buf::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 class="doc-anchor" href="#cancel-safety-3">§</a>Cancel safety</h5>
|
||
<p>If <code>write_all_buf</code> is used as the event in a
|
||
<a href="../macro.select.html" title="macro tokio::select"><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" title="method bytes::buf::buf_impl::Buf::advance">advanced</a> by the amount of bytes that have been
|
||
partially written.</p>
|
||
<h5 id="examples-3"><a class="doc-anchor" href="#examples-3">§</a>Examples</h5>
|
||
<p><a href="../fs/struct.File.html" title="struct tokio::fs::File"><code>File</code></a> implements <a href="trait.AsyncWrite.html" title="trait tokio::io::AsyncWrite"><code>AsyncWrite</code></a> and <a href="https://doc.rust-lang.org/1.93.1/std/io/cursor/struct.Cursor.html" title="struct std::io::cursor::Cursor"><code>Cursor</code></a><code><&[u8]></code> implements <a href="../../bytes/buf/buf_impl/trait.Buf.html" title="trait bytes::buf::buf_impl::Buf"><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="attr">#[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>;
|
||
file.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_all" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#387-392">Source</a><h4 class="code-header">fn <a href="#method.write_all" class="fn">write_all</a><'a>(&'a mut self, src: &'a [<a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>]) -> WriteAll<'a, Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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" title="method tokio::io::AsyncWriteExt::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 class="doc-anchor" href="#cancel-safety-4">§</a>Cancel safety</h5>
|
||
<p>This method is not cancellation safe. If it is used as the event
|
||
in a <a href="../macro.select.html" title="macro tokio::select"><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 class="doc-anchor" href="#errors-2">§</a>Errors</h5>
|
||
<p>This function will return the first error that <a href="trait.AsyncWriteExt.html#method.write" title="method tokio::io::AsyncWriteExt::write"><code>write</code></a> returns.</p>
|
||
<h5 id="examples-4"><a class="doc-anchor" href="#examples-4">§</a>Examples</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="attr">#[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>;
|
||
file.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||
<span class="prelude-val">Ok</span>(())
|
||
}</code></pre></div></div></details><details class="toggle method-toggle" open><summary><section id="method.write_u8" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u8" class="fn">write_u8</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u8.html">u8</a>) -> WriteU8<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-3">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-5"><a class="doc-anchor" href="#examples-5">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i8" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i8" class="fn">write_i8</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i8.html">i8</a>) -> WriteI8<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-4">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-6"><a class="doc-anchor" href="#examples-6">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u16" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u16" class="fn">write_u16</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u16.html">u16</a>) -> WriteU16<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-5">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-7"><a class="doc-anchor" href="#examples-7">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i16" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i16" class="fn">write_i16</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i16.html">i16</a>) -> WriteI16<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-6">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-8"><a class="doc-anchor" href="#examples-8">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u32" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u32" class="fn">write_u32</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -> WriteU32<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-7">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-9"><a class="doc-anchor" href="#examples-9">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i32" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i32" class="fn">write_i32</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i32.html">i32</a>) -> WriteI32<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-8">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-10"><a class="doc-anchor" href="#examples-10">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u64" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u64" class="fn">write_u64</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u64.html">u64</a>) -> WriteU64<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-9">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-11"><a class="doc-anchor" href="#examples-11">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i64" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i64" class="fn">write_i64</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i64.html">i64</a>) -> WriteI64<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-10">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-12"><a class="doc-anchor" href="#examples-12">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u128" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u128" class="fn">write_u128</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u128.html">u128</a>) -> WriteU128<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-11">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-13"><a class="doc-anchor" href="#examples-13">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i128" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i128" class="fn">write_i128</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i128.html">i128</a>) -> WriteI128<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-12">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-14"><a class="doc-anchor" href="#examples-14">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_f32" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_f32" class="fn">write_f32</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f32.html">f32</a>) -> WriteF32<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-13">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-15"><a class="doc-anchor" href="#examples-15">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_f64" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_f64" class="fn">write_f64</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f64.html">f64</a>) -> WriteF64<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-14">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-16"><a class="doc-anchor" href="#examples-16">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u16_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u16_le" class="fn">write_u16_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u16.html">u16</a>) -> WriteU16Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-15">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-17"><a class="doc-anchor" href="#examples-17">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i16_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i16_le" class="fn">write_i16_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i16.html">i16</a>) -> WriteI16Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-16">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-18"><a class="doc-anchor" href="#examples-18">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u32_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u32_le" class="fn">write_u32_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u32.html">u32</a>) -> WriteU32Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-17">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-19"><a class="doc-anchor" href="#examples-19">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i32_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i32_le" class="fn">write_i32_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i32.html">i32</a>) -> WriteI32Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-18">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-20"><a class="doc-anchor" href="#examples-20">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u64_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u64_le" class="fn">write_u64_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u64.html">u64</a>) -> WriteU64Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-19">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-21"><a class="doc-anchor" href="#examples-21">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i64_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i64_le" class="fn">write_i64_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i64.html">i64</a>) -> WriteI64Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-20">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-22"><a class="doc-anchor" href="#examples-22">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_u128_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_u128_le" class="fn">write_u128_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.u128.html">u128</a>) -> WriteU128Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-21">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-23"><a class="doc-anchor" href="#examples-23">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_i128_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_i128_le" class="fn">write_i128_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.i128.html">i128</a>) -> WriteI128Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-22">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-24"><a class="doc-anchor" href="#examples-24">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_f32_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_f32_le" class="fn">write_f32_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f32.html">f32</a>) -> WriteF32Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-23">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-25"><a class="doc-anchor" href="#examples-25">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.write_f64_le" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#394-1236">Source</a><h4 class="code-header">fn <a href="#method.write_f64_le" class="fn">write_f64_le</a>(&mut self, n: <a class="primitive" href="https://doc.rust-lang.org/1.93.1/std/primitive.f64.html">f64</a>) -> WriteF64Le<&mut Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-24">§</a>Errors</h5>
|
||
<p>This method returns the same errors as <a href="trait.AsyncWriteExt.html#method.write_all" title="method tokio::io::AsyncWriteExt::write_all"><code>AsyncWriteExt::write_all</code></a>.</p>
|
||
<h5 id="examples-26"><a class="doc-anchor" href="#examples-26">§</a>Examples</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="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="toggle method-toggle" open><summary><section id="method.flush" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#1281-1286">Source</a><h4 class="code-header">fn <a href="#method.flush" class="fn">flush</a>(&mut self) -> Flush<'_, Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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 class="doc-anchor" href="#errors-25">§</a>Errors</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="cancel-safety-5"><a class="doc-anchor" href="#cancel-safety-5">§</a>Cancel safety</h5>
|
||
<p>This method is cancel safe.</p>
|
||
<p>If <code>flush</code> is used as the event in a <a href="../macro.select.html" title="macro tokio::select"><code>tokio::select!</code></a>
|
||
statement and some other branch completes first, then the data in the
|
||
buffered data in this <code>AsyncWrite</code> may have been partially flushed.
|
||
However, it is guaranteed that the buffer is advanced by the amount of
|
||
bytes that have been partially flushed.</p>
|
||
<h5 id="examples-27"><a class="doc-anchor" href="#examples-27">§</a>Examples</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="attr">#[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="toggle method-toggle" open><summary><section id="method.shutdown" class="method"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#1323-1328">Source</a><h4 class="code-header">fn <a href="#method.shutdown" class="fn">shutdown</a>(&mut self) -> Shutdown<'_, Self><div class="where">where
|
||
Self: <a class="trait" href="https://doc.rust-lang.org/1.93.1/core/marker/trait.Unpin.html" title="trait core::marker::Unpin">Unpin</a>,</div></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"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><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" title="method tokio::io::AsyncWriteExt::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 class="doc-anchor" href="#examples-28">§</a>Examples</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="attr">#[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="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.93.1/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-AsyncWriteExt-for-W" class="impl"><a class="src rightside" href="../../src/tokio/io/util/async_write_ext.rs.html#1332">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/1.93.1/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="../../trait.impl/tokio/io/util/async_write_ext/trait.AsyncWriteExt.js" async></script></section></div></main></body></html> |