267 lines
No EOL
20 KiB
HTML
267 lines
No EOL
20 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="API documentation for the Rust `Write` trait in crate `bitflags`.">
|
||
<meta name="keywords" content="rust, rustlang, rust-lang, Write">
|
||
|
||
<title>bitflags::__core::io::Write - Rust</title>
|
||
|
||
<link rel="stylesheet" type="text/css" href="../../../rustdoc.css">
|
||
<link rel="stylesheet" type="text/css" href="../../../main.css">
|
||
|
||
|
||
|
||
|
||
</head>
|
||
<body class="rustdoc">
|
||
<!--[if lte IE 8]>
|
||
<div class="warning">
|
||
This old browser is unsupported and will most likely display funky
|
||
things.
|
||
</div>
|
||
<![endif]-->
|
||
|
||
|
||
|
||
<nav class="sidebar">
|
||
|
||
<p class='location'><a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a href='index.html'>io</a></p><script>window.sidebarCurrent = {name: 'Write', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script>
|
||
</nav>
|
||
|
||
<nav class="sub">
|
||
<form class="search-form js-only">
|
||
<div class="search-container">
|
||
<input class="search-input" name="search"
|
||
autocomplete="off"
|
||
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
|
||
type="search">
|
||
</div>
|
||
</form>
|
||
</nav>
|
||
|
||
<section id='main' class="content trait">
|
||
<h1 class='fqn'><span class='in-band'>Trait <a href='../../index.html'>bitflags</a>::<wbr><a href='../index.html'>__core</a>::<wbr><a href='index.html'>io</a>::<wbr><a class='trait' href=''>Write</a></span><span class='out-of-band'><span id='render-detail'>
|
||
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
|
||
[<span class='inner'>−</span>]
|
||
</a>
|
||
</span><a id='src-4924' class='srclink' href='https://doc.rust-lang.org/nightly/std/io/trait.Write.html?gotosrc=4924' title='goto source code'>[src]</a></span></h1>
|
||
<pre class='rust trait'>pub trait Write {
|
||
fn <a href='#tymethod.write' class='fnname'>write</a>(&mut self, buf: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>&[</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u8.html'>u8</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>]</a>) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.usize.html'>usize</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>>;
|
||
fn <a href='#tymethod.flush' class='fnname'>flush</a>(&mut self) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>>;
|
||
|
||
fn <a href='#method.write_all' class='fnname'>write_all</a>(&mut self, buf: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>&[</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u8.html'>u8</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>]</a>) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>> { ... }
|
||
fn <a href='#method.write_fmt' class='fnname'>write_fmt</a>(&mut self, fmt: <a class='struct' href='../../../bitflags/__core/fmt/struct.Arguments.html' title='bitflags::__core::fmt::Arguments'>Arguments</a>) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>> { ... }
|
||
fn <a href='#method.by_ref' class='fnname'>by_ref</a>(&mut self) -> &mut Self { ... }
|
||
}</pre><div class='docblock'><p>A trait for objects which are byte-oriented sinks.</p>
|
||
|
||
<p>Implementors of the <code>Write</code> trait are sometimes called 'writers'.</p>
|
||
|
||
<p>Writers are defined by two required methods, <code>write()</code> and <code>flush()</code>:</p>
|
||
|
||
<ul>
|
||
<li><p>The <code>write()</code> method will attempt to write some data into the object,
|
||
returning how many bytes were successfully written.</p></li>
|
||
<li><p>The <code>flush()</code> method is useful for adaptors and explicit buffers
|
||
themselves for ensuring that all buffered data has been pushed out to the
|
||
'true sink'.</p></li>
|
||
</ul>
|
||
|
||
<p>Writers are intended to be composable with one another. Many implementors
|
||
throughout <code>std::io</code> take and provide types which implement the <code>Write</code>
|
||
trait.</p>
|
||
|
||
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>prelude</span>::<span class='op'>*</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fs</span>::<span class='ident'>File</span>;
|
||
|
||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>buffer</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>File</span>::<span class='ident'>create</span>(<span class='string'>"foo.txt"</span>));
|
||
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>buffer</span>.<span class='ident'>write</span>(<span class='string'>b"some bytes"</span>));</pre>
|
||
</div>
|
||
<h2 id='required-methods'>Required Methods</h2>
|
||
<div class='methods'>
|
||
<h3 id='tymethod.write' class='method stab '><code>fn <a href='#tymethod.write' class='fnname'>write</a>(&mut self, buf: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>&[</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u8.html'>u8</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>]</a>) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.usize.html'>usize</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>></code></h3><div class='docblock'><p>Write a buffer into this object, returning how many bytes were written.</p>
|
||
|
||
<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>
|
||
|
||
<p>Calls to <code>write</code> are not guaranteed to block waiting for data to be
|
||
written, and a write which would otherwise block can be indicated through
|
||
an <code>Err</code> variant.</p>
|
||
|
||
<p>If the return value is <code>Ok(n)</code> then it must be guaranteed that
|
||
<code>0 <= 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>
|
||
|
||
<h1 id='errors' class='section-header'><a href='#errors'>Errors</a></h1>
|
||
<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>
|
||
|
||
<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>prelude</span>::<span class='op'>*</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fs</span>::<span class='ident'>File</span>;
|
||
|
||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>buffer</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>File</span>::<span class='ident'>create</span>(<span class='string'>"foo.txt"</span>));
|
||
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>buffer</span>.<span class='ident'>write</span>(<span class='string'>b"some bytes"</span>));</pre>
|
||
</div><h3 id='tymethod.flush' class='method stab '><code>fn <a href='#tymethod.flush' class='fnname'>flush</a>(&mut self) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>></code></h3><div class='docblock'><p>Flush this output stream, ensuring that all intermediately buffered
|
||
contents reach their destination.</p>
|
||
|
||
<h1 id='errors-1' class='section-header'><a href='#errors-1'>Errors</a></h1>
|
||
<p>It is considered an error if not all bytes could be written due to
|
||
I/O errors or EOF being reached.</p>
|
||
|
||
<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>prelude</span>::<span class='op'>*</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>BufWriter</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fs</span>::<span class='ident'>File</span>;
|
||
|
||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>buffer</span> <span class='op'>=</span> <span class='ident'>BufWriter</span>::<span class='ident'>new</span>(<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>File</span>::<span class='ident'>create</span>(<span class='string'>"foo.txt"</span>)));
|
||
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>buffer</span>.<span class='ident'>write</span>(<span class='string'>b"some bytes"</span>));
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>buffer</span>.<span class='ident'>flush</span>());</pre>
|
||
</div></div>
|
||
<h2 id='provided-methods'>Provided Methods</h2>
|
||
<div class='methods'>
|
||
<h3 id='method.write_all' class='method stab '><code>fn <a href='#method.write_all' class='fnname'>write_all</a>(&mut self, buf: <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>&[</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u8.html'>u8</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>]</a>) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>></code></h3><div class='docblock'><p>Attempts to write an entire buffer into this write.</p>
|
||
|
||
<p>This method will continuously call <code>write</code> while there is more data to
|
||
write. This method will not return until the entire buffer has been
|
||
successfully written or an error occurs. The first error generated from
|
||
this method will be returned.</p>
|
||
|
||
<h1 id='errors-2' class='section-header'><a href='#errors-2'>Errors</a></h1>
|
||
<p>This function will return the first error that <code>write</code> returns.</p>
|
||
|
||
<h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>prelude</span>::<span class='op'>*</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fs</span>::<span class='ident'>File</span>;
|
||
|
||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>buffer</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>File</span>::<span class='ident'>create</span>(<span class='string'>"foo.txt"</span>));
|
||
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>buffer</span>.<span class='ident'>write_all</span>(<span class='string'>b"some bytes"</span>));</pre>
|
||
</div><h3 id='method.write_fmt' class='method stab '><code>fn <a href='#method.write_fmt' class='fnname'>write_fmt</a>(&mut self, fmt: <a class='struct' href='../../../bitflags/__core/fmt/struct.Arguments.html' title='bitflags::__core::fmt::Arguments'>Arguments</a>) -> <a class='enum' href='../../../bitflags/__core/result/enum.Result.html' title='bitflags::__core::result::Result'>Result</a><<a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.tuple.html'>()</a>, <a class='struct' href='../../../bitflags/__core/io/struct.Error.html' title='bitflags::__core::io::Error'>Error</a>></code></h3><div class='docblock'><p>Writes a formatted string into this writer, returning any error
|
||
encountered.</p>
|
||
|
||
<p>This method is primarily used to interface with the
|
||
<a href="../macro.format_args!.html"><code>format_args!</code></a> macro, but it is rare that this should
|
||
explicitly be called. The <a href="../macro.write!.html"><code>write!</code></a> macro should be favored to
|
||
invoke this method instead.</p>
|
||
|
||
<p>This function internally uses the <a href="#method.write_all"><code>write_all</code></a> method on
|
||
this trait and hence will continuously write data so long as no errors
|
||
are received. This also means that partial writes are not indicated in
|
||
this signature.</p>
|
||
|
||
<h1 id='errors-3' class='section-header'><a href='#errors-3'>Errors</a></h1>
|
||
<p>This function will return any I/O error reported while formatting.</p>
|
||
|
||
<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>prelude</span>::<span class='op'>*</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fs</span>::<span class='ident'>File</span>;
|
||
|
||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>buffer</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>File</span>::<span class='ident'>create</span>(<span class='string'>"foo.txt"</span>));
|
||
|
||
<span class='comment'>// this call</span>
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='macro'>write</span><span class='macro'>!</span>(<span class='ident'>buffer</span>, <span class='string'>"{:.*}"</span>, <span class='number'>2</span>, <span class='number'>1.234567</span>));
|
||
<span class='comment'>// turns into this:</span>
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>buffer</span>.<span class='ident'>write_fmt</span>(<span class='macro'>format_args</span><span class='macro'>!</span>(<span class='string'>"{:.*}"</span>, <span class='number'>2</span>, <span class='number'>1.234567</span>)));</pre>
|
||
</div><h3 id='method.by_ref' class='method stab '><code>fn <a href='#method.by_ref' class='fnname'>by_ref</a>(&mut self) -> &mut Self</code></h3><div class='docblock'><p>Creates a "by reference" adaptor for this instance of <code>Write</code>.</p>
|
||
|
||
<p>The returned adaptor also implements <code>Write</code> and will simply borrow this
|
||
current writer.</p>
|
||
|
||
<h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1>
|
||
<pre class='rust rust-example-rendered'>
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>io</span>::<span class='ident'>Write</span>;
|
||
<span class='kw'>use</span> <span class='ident'>std</span>::<span class='ident'>fs</span>::<span class='ident'>File</span>;
|
||
|
||
<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>buffer</span> <span class='op'>=</span> <span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>File</span>::<span class='ident'>create</span>(<span class='string'>"foo.txt"</span>));
|
||
|
||
<span class='kw'>let</span> <span class='ident'>reference</span> <span class='op'>=</span> <span class='ident'>buffer</span>.<span class='ident'>by_ref</span>();
|
||
|
||
<span class='comment'>// we can use reference just like our original buffer</span>
|
||
<span class='macro'>try</span><span class='macro'>!</span>(<span class='ident'>reference</span>.<span class='ident'>write_all</span>(<span class='string'>b"some bytes"</span>));</pre>
|
||
</div></div>
|
||
<h2 id='implementors'>Implementors</h2>
|
||
<ul class='item-list' id='implementors-list'>
|
||
<li><code>impl<'a> Write for <a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>&'a mut [</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.u8.html'>u8</a><a class='primitive' href='https://doc.rust-lang.org/nightly/bitflags/primitive.slice.html'>]</a></code></li>
|
||
</ul><script type="text/javascript" async
|
||
src="../../../implementors/std/io/trait.Write.js">
|
||
</script></section>
|
||
<section id='search' class="content hidden"></section>
|
||
|
||
<section class="footer"></section>
|
||
|
||
<aside id="help" class="hidden">
|
||
<div>
|
||
<h1 class="hidden">Help</h1>
|
||
|
||
<div class="shortcuts">
|
||
<h2>Keyboard Shortcuts</h2>
|
||
|
||
<dl>
|
||
<dt>?</dt>
|
||
<dd>Show this help dialog</dd>
|
||
<dt>S</dt>
|
||
<dd>Focus the search field</dd>
|
||
<dt>⇤</dt>
|
||
<dd>Move up in search results</dd>
|
||
<dt>⇥</dt>
|
||
<dd>Move down in search results</dd>
|
||
<dt>⏎</dt>
|
||
<dd>Go to active search result</dd>
|
||
</dl>
|
||
</div>
|
||
|
||
<div class="infos">
|
||
<h2>Search Tricks</h2>
|
||
|
||
<p>
|
||
Prefix searches with a type followed by a colon (e.g.
|
||
<code>fn:</code>) to restrict the search to a given type.
|
||
</p>
|
||
|
||
<p>
|
||
Accepted types are: <code>fn</code>, <code>mod</code>,
|
||
<code>struct</code>, <code>enum</code>,
|
||
<code>trait</code>, <code>type</code>, <code>macro</code>,
|
||
and <code>const</code>.
|
||
</p>
|
||
|
||
<p>
|
||
Search functions by type signature (e.g.
|
||
<code>vec -> usize</code> or <code>* -> vec</code>)
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
|
||
|
||
|
||
<script>
|
||
window.rootPath = "../../../";
|
||
window.currentCrate = "bitflags";
|
||
window.playgroundUrl = "";
|
||
</script>
|
||
<script src="../../../jquery.js"></script>
|
||
<script src="../../../main.js"></script>
|
||
|
||
<script defer src="../../../search-index.js"></script>
|
||
</body>
|
||
</html> |