mentat/docs/apis/rust/tokio/io/struct.Error.html
2018-06-22 12:08:32 +01:00

330 lines
No EOL
42 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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 `Error` struct in crate `tokio`.">
<meta name="keywords" content="rust, rustlang, rust-lang, Error">
<title>tokio::io::Error - Rust</title>
<link rel="stylesheet" type="text/css" href="../../normalize.css">
<link rel="stylesheet" type="text/css" href="../../rustdoc.css"
id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="../../dark.css">
<link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle">
<script src="../../storage.js"></script>
</head>
<body class="rustdoc struct">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<div class="sidebar-menu">&#9776;</div>
<p class='location'>Struct Error</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#methods">Methods</a><div class="sidebar-links"><a href="#method.new">new</a><a href="#method.last_os_error">last_os_error</a><a href="#method.from_raw_os_error">from_raw_os_error</a><a href="#method.raw_os_error">raw_os_error</a><a href="#method.get_ref">get_ref</a><a href="#method.get_mut">get_mut</a><a href="#method.into_inner">into_inner</a><a href="#method.kind">kind</a></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Display">Display</a><a href="#impl-From%3CErrorKind%3E">From&lt;ErrorKind&gt;</a><a href="#impl-From%3CNulError%3E">From&lt;NulError&gt;</a><a href="#impl-From%3CIntoInnerError%3CW%3E%3E">From&lt;IntoInnerError&lt;W&gt;&gt;</a><a href="#impl-Error">Error</a><a href="#impl-Debug">Debug</a></div><a class="sidebar-title" href="#synthetic-implementations">Auto Trait Implementations</a><div class="sidebar-links"><a href="#impl-Send">Send</a><a href="#impl-Sync">Sync</a></div></div><p class='location'><a href='../index.html'>tokio</a>::<wbr><a href='index.html'>io</a></p><script>window.sidebarCurrent = {name: 'Error', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
</nav>
<div class="theme-picker">
<button id="theme-picker" aria-label="Pick another theme!">
<img src="../../brush.svg" width="18" alt="Pick another theme!">
</button>
<div id="theme-choices"></div>
</div>
<script src="../../theme.js"></script>
<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"><h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>tokio</a>::<wbr><a href='index.html'>io</a>::<wbr><a class="struct" href=''>Error</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#66-68' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust struct'>pub struct Error { /* fields omitted */ }</pre></div><div class='docblock'><p>The error type for I/O operations of the <a href="../io/trait.Read.html"><code>Read</code></a>, <a href="../io/trait.Write.html"><code>Write</code></a>, <a href="../io/trait.Seek.html"><code>Seek</code></a>, and
associated traits.</p>
<p>Errors mostly originate from the underlying OS, but custom instances of
<code>Error</code> can be created with crafted error messages and a particular value of
<a href="enum.ErrorKind.html"><code>ErrorKind</code></a>.</p>
</div>
<h2 id='methods' class='small-section-header'>
Methods<a href='#methods' class='anchor'></a>
</h2>
<h3 id='impl' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#232-515' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.new' class='fnname'>new</a>&lt;E&gt;(kind: <a class="enum" href="../../tokio/io/enum.ErrorKind.html" title="enum tokio::io::ErrorKind">ErrorKind</a>, error: E) -&gt; <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;E: <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.Into.html" title="trait core::convert::Into">Into</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> + 'static + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt;&gt;,&nbsp;</span></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#252-256' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a new I/O error from a known kind of error as well as an
arbitrary error payload.</p>
<p>This function is used to generically create I/O errors which do not
originate from the OS itself. The <code>error</code> argument is an arbitrary
payload which will be contained in this <code>Error</code>.</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">Error</span>, <span class="ident">ErrorKind</span>};
<span class="comment">// errors can be created from strings</span>
<span class="kw">let</span> <span class="ident">custom_error</span> <span class="op">=</span> <span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">Other</span>, <span class="string">&quot;oh no!&quot;</span>);
<span class="comment">// errors can also be created from other errors</span>
<span class="kw">let</span> <span class="ident">custom_error2</span> <span class="op">=</span> <span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">Interrupted</span>, <span class="ident">custom_error</span>);</pre>
</div><h4 id='method.last_os_error' class="method"><span id='last_os_error.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.last_os_error' class='fnname'>last_os_error</a>() -&gt; <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#281-283' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns an error representing the last OS error which occurred.</p>
<p>This function reads the value of <code>errno</code> for the target platform (e.g.
<code>GetLastError</code> on Windows) and will return a corresponding instance of
<code>Error</code> for the error code.</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">Error</span>;
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;last OS error: {:?}&quot;</span>, <span class="ident">Error</span>::<span class="ident">last_os_error</span>());</pre>
</div><h4 id='method.from_raw_os_error' class="method"><span id='from_raw_os_error.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.from_raw_os_error' class='fnname'>from_raw_os_error</a>(code: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>) -&gt; <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#311-313' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Creates a new instance of an <code>Error</code> from a particular OS error code.</p>
<h1 id="examples-2" class="section-header"><a href="#examples-2">Examples</a></h1>
<p>On Linux:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>;
<span class="kw">let</span> <span class="ident">error</span> <span class="op">=</span> <span class="ident">io</span>::<span class="ident">Error</span>::<span class="ident">from_raw_os_error</span>(<span class="number">22</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">error</span>.<span class="ident">kind</span>(), <span class="ident">io</span>::<span class="ident">ErrorKind</span>::<span class="ident">InvalidInput</span>);</pre>
<p>On Windows:</p>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>;
<span class="kw">let</span> <span class="ident">error</span> <span class="op">=</span> <span class="ident">io</span>::<span class="ident">Error</span>::<span class="ident">from_raw_os_error</span>(<span class="number">10022</span>);
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">error</span>.<span class="ident">kind</span>(), <span class="ident">io</span>::<span class="ident">ErrorKind</span>::<span class="ident">InvalidInput</span>);</pre>
</div><h4 id='method.raw_os_error' class="method"><span id='raw_os_error.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.raw_os_error' class='fnname'>raw_os_error</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#342-348' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the OS error that this error represents (if any).</p>
<p>If this <code>Error</code> was constructed via <code>last_os_error</code> or
<code>from_raw_os_error</code>, then this function will return <code>Some</code>, otherwise
it will return <code>None</code>.</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">Error</span>, <span class="ident">ErrorKind</span>};
<span class="kw">fn</span> <span class="ident">print_os_error</span>(<span class="ident">err</span>: <span class="kw-2">&amp;</span><span class="ident">Error</span>) {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">raw_os_err</span>) <span class="op">=</span> <span class="ident">err</span>.<span class="ident">raw_os_error</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;raw OS error: {:?}&quot;</span>, <span class="ident">raw_os_err</span>);
} <span class="kw">else</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Not an OS error&quot;</span>);
}
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// Will print &quot;raw OS error: ...&quot;.</span>
<span class="ident">print_os_error</span>(<span class="kw-2">&amp;</span><span class="ident">Error</span>::<span class="ident">last_os_error</span>());
<span class="comment">// Will print &quot;Not an OS error&quot;.</span>
<span class="ident">print_os_error</span>(<span class="kw-2">&amp;</span><span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">Other</span>, <span class="string">&quot;oh no!&quot;</span>));
}</pre>
</div><h4 id='method.get_ref' class="method"><span id='get_ref.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.get_ref' class='fnname'>get_ref</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;(<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> + 'static + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>)&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#376-382' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns a reference to the inner error wrapped by this error (if any).</p>
<p>If this <code>Error</code> was constructed via <code>new</code> then this function will
return <code>Some</code>, otherwise it will return <code>None</code>.</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">Error</span>, <span class="ident">ErrorKind</span>};
<span class="kw">fn</span> <span class="ident">print_error</span>(<span class="ident">err</span>: <span class="kw-2">&amp;</span><span class="ident">Error</span>) {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">inner_err</span>) <span class="op">=</span> <span class="ident">err</span>.<span class="ident">get_ref</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Inner error: {:?}&quot;</span>, <span class="ident">inner_err</span>);
} <span class="kw">else</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;No inner error&quot;</span>);
}
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// Will print &quot;No inner error&quot;.</span>
<span class="ident">print_error</span>(<span class="kw-2">&amp;</span><span class="ident">Error</span>::<span class="ident">last_os_error</span>());
<span class="comment">// Will print &quot;Inner error: ...&quot;.</span>
<span class="ident">print_error</span>(<span class="kw-2">&amp;</span><span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">Other</span>, <span class="string">&quot;oh no!&quot;</span>));
}</pre>
</div><h4 id='method.get_mut' class="method"><span id='get_mut.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.get_mut' class='fnname'>get_mut</a>(&amp;mut self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut (<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> + 'static + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>)&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#447-453' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns a mutable reference to the inner error wrapped by this error
(if any).</p>
<p>If this <code>Error</code> was constructed via <code>new</code> then this function will
return <code>Some</code>, otherwise it will return <code>None</code>.</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">Error</span>, <span class="ident">ErrorKind</span>};
<span class="kw">use</span> <span class="ident">std</span>::{<span class="ident">error</span>, <span class="ident">fmt</span>};
<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fmt</span>::<span class="ident">Display</span>;
<span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Debug</span>)]</span>
<span class="kw">struct</span> <span class="ident">MyError</span> {
<span class="ident">v</span>: <span class="ident">String</span>,
}
<span class="kw">impl</span> <span class="ident">MyError</span> {
<span class="kw">fn</span> <span class="ident">new</span>() <span class="op">-&gt;</span> <span class="ident">MyError</span> {
<span class="ident">MyError</span> {
<span class="ident">v</span>: <span class="string">&quot;oh no!&quot;</span>.<span class="ident">to_string</span>()
}
}
<span class="kw">fn</span> <span class="ident">change_message</span>(<span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">new_message</span>: <span class="kw-2">&amp;</span><span class="ident">str</span>) {
<span class="self">self</span>.<span class="ident">v</span> <span class="op">=</span> <span class="ident">new_message</span>.<span class="ident">to_string</span>();
}
}
<span class="kw">impl</span> <span class="ident">error</span>::<span class="ident">Error</span> <span class="kw">for</span> <span class="ident">MyError</span> {
<span class="kw">fn</span> <span class="ident">description</span>(<span class="kw-2">&amp;</span><span class="self">self</span>) <span class="op">-&gt;</span> <span class="kw-2">&amp;</span><span class="ident">str</span> { <span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">v</span> }
}
<span class="kw">impl</span> <span class="ident">Display</span> <span class="kw">for</span> <span class="ident">MyError</span> {
<span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&amp;</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&amp;</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span>) <span class="op">-&gt;</span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> {
<span class="macro">write</span><span class="macro">!</span>(<span class="ident">f</span>, <span class="string">&quot;MyError: {}&quot;</span>, <span class="kw-2">&amp;</span><span class="self">self</span>.<span class="ident">v</span>)
}
}
<span class="kw">fn</span> <span class="ident">change_error</span>(<span class="kw-2">mut</span> <span class="ident">err</span>: <span class="ident">Error</span>) <span class="op">-&gt;</span> <span class="ident">Error</span> {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">inner_err</span>) <span class="op">=</span> <span class="ident">err</span>.<span class="ident">get_mut</span>() {
<span class="ident">inner_err</span>.<span class="ident">downcast_mut</span>::<span class="op">&lt;</span><span class="ident">MyError</span><span class="op">&gt;</span>().<span class="ident">unwrap</span>().<span class="ident">change_message</span>(<span class="string">&quot;I&#39;ve been changed!&quot;</span>);
}
<span class="ident">err</span>
}
<span class="kw">fn</span> <span class="ident">print_error</span>(<span class="ident">err</span>: <span class="kw-2">&amp;</span><span class="ident">Error</span>) {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">inner_err</span>) <span class="op">=</span> <span class="ident">err</span>.<span class="ident">get_ref</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Inner error: {}&quot;</span>, <span class="ident">inner_err</span>);
} <span class="kw">else</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;No inner error&quot;</span>);
}
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// Will print &quot;No inner error&quot;.</span>
<span class="ident">print_error</span>(<span class="kw-2">&amp;</span><span class="ident">change_error</span>(<span class="ident">Error</span>::<span class="ident">last_os_error</span>()));
<span class="comment">// Will print &quot;Inner error: ...&quot;.</span>
<span class="ident">print_error</span>(<span class="kw-2">&amp;</span><span class="ident">change_error</span>(<span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">Other</span>, <span class="ident">MyError</span>::<span class="ident">new</span>())));
}</pre>
</div><h4 id='method.into_inner' class="method"><span id='into_inner.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.into_inner' class='fnname'>into_inner</a>(self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a>&lt;<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> + 'static + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>&gt;&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#481-487' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Consumes the <code>Error</code>, returning its inner error (if any).</p>
<p>If this <code>Error</code> was constructed via <code>new</code> then this function will
return <code>Some</code>, otherwise it will return <code>None</code>.</p>
<h1 id="examples-6" class="section-header"><a href="#examples-6">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">Error</span>, <span class="ident">ErrorKind</span>};
<span class="kw">fn</span> <span class="ident">print_error</span>(<span class="ident">err</span>: <span class="ident">Error</span>) {
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">inner_err</span>) <span class="op">=</span> <span class="ident">err</span>.<span class="ident">into_inner</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;Inner error: {}&quot;</span>, <span class="ident">inner_err</span>);
} <span class="kw">else</span> {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;No inner error&quot;</span>);
}
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// Will print &quot;No inner error&quot;.</span>
<span class="ident">print_error</span>(<span class="ident">Error</span>::<span class="ident">last_os_error</span>());
<span class="comment">// Will print &quot;Inner error: ...&quot;.</span>
<span class="ident">print_error</span>(<span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">Other</span>, <span class="string">&quot;oh no!&quot;</span>));
}</pre>
</div><h4 id='method.kind' class="method"><span id='kind.v' class='invisible'><table class='table-display'><tbody><tr><td><code>pub fn <a href='#method.kind' class='fnname'>kind</a>(&amp;self) -&gt; <a class="enum" href="../../tokio/io/enum.ErrorKind.html" title="enum tokio::io::ErrorKind">ErrorKind</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#508-514' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Returns the corresponding <code>ErrorKind</code> for this error.</p>
<h1 id="examples-7" class="section-header"><a href="#examples-7">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">Error</span>, <span class="ident">ErrorKind</span>};
<span class="kw">fn</span> <span class="ident">print_error</span>(<span class="ident">err</span>: <span class="ident">Error</span>) {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">&quot;{:?}&quot;</span>, <span class="ident">err</span>.<span class="ident">kind</span>());
}
<span class="kw">fn</span> <span class="ident">main</span>() {
<span class="comment">// Will print &quot;No inner error&quot;.</span>
<span class="ident">print_error</span>(<span class="ident">Error</span>::<span class="ident">last_os_error</span>());
<span class="comment">// Will print &quot;Inner error: ...&quot;.</span>
<span class="ident">print_error</span>(<span class="ident">Error</span>::<span class="ident">new</span>(<span class="ident">ErrorKind</span>::<span class="ident">AddrInUse</span>, <span class="string">&quot;oh no!&quot;</span>));
}</pre>
</div></div>
<h2 id='implementations' class='small-section-header'>
Trait Implementations<a href='#implementations' class='anchor'></a>
</h2>
<div id='implementations-list'>
<h3 id='impl-Display' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-Display' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#532-543' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, fmt: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#533-542' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html#tymethod.fmt">Read more</a></p>
</div></div><h3 id='impl-From%3CErrorKind%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="enum" href="../../tokio/io/enum.ErrorKind.html" title="enum tokio::io::ErrorKind">ErrorKind</a>&gt; for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-From%3CErrorKind%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.14.0'>1.14.0</div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#223-230' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='docblock'><p>Intended for use for errors not exposed to the user, where allocating onto
the heap (for normal construction via Error::new) is too costly.</p>
</div><div class='impl-items'><h4 id='method.from' class="method"><span id='from.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(kind: <a class="enum" href="../../tokio/io/enum.ErrorKind.html" title="enum tokio::io::ErrorKind">ErrorKind</a>) -&gt; <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#225-229' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3CNulError%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/c_str/struct.NulError.html" title="struct std::ffi::c_str::NulError">NulError</a>&gt; for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-From%3CNulError%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/ffi/c_str.rs.html#801-806' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-1' class="method"><span id='from.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(<a class="struct" href="https://doc.rust-lang.org/nightly/std/ffi/c_str/struct.NulError.html" title="struct std::ffi::c_str::NulError">NulError</a>) -&gt; <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/ffi/c_str.rs.html#802-805' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 id='impl-From%3CIntoInnerError%3CW%3E%3E' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl&lt;W&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.From.html" title="trait core::convert::From">From</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/std/io/buffered/struct.IntoInnerError.html" title="struct std::io::buffered::IntoInnerError">IntoInnerError</a>&lt;W&gt;&gt; for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-From%3CIntoInnerError%3CW%3E%3E' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/buffered.rs.html#688-690' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.from-2' class="method"><span id='from.v-2' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(iie: <a class="struct" href="https://doc.rust-lang.org/nightly/std/io/buffered/struct.IntoInnerError.html" title="struct std::io::buffered::IntoInnerError">IntoInnerError</a>&lt;W&gt;) -&gt; <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/buffered.rs.html#689' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Performs the conversion.</p>
</div></div><h3 id='impl-Error' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-Error' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#546-561' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.description' class="method"><span id='description.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/std/error/trait.Error.html#tymethod.description' class='fnname'>description</a>(&amp;self) -&gt; &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a></code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#547-552' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>A short description of the error. <a href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html#tymethod.description">Read more</a></p>
</div><h4 id='method.cause' class="method"><span id='cause.v' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/std/error/trait.Error.html#method.cause' class='fnname'>cause</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#554-560' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>The lower-level cause of this error, if any. <a href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html#method.cause">Read more</a></p>
</div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-Debug' class='anchor'></a></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#71-75' title='goto source code'>[src]</a></span></td></tr></tbody></table></h3><div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><table class='table-display'><tbody><tr><td><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Error.html" title="struct core::fmt::Error">Error</a>&gt;</code></span></td><td><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='https://doc.rust-lang.org/nightly/src/std/io/error.rs.html#72-74' title='goto source code'>[src]</a></td></tr></tbody></table></span></h4><div class='docblock'><p>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></p>
</div></div></div>
<h2 id='synthetic-implementations' class='small-section-header'>
Auto Trait Implementations<a href='#synthetic-implementations' class='anchor'></a>
</h2>
<div id='synthetic-implementations-list'>
<h3 id='impl-Send' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-Send' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div><h3 id='impl-Sync' class='impl'><span class='in-band'><table class='table-display'><tbody><tr><td><code>impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="../../tokio/io/struct.Error.html" title="struct tokio::io::Error">Error</a></code><a href='#impl-Sync' class='anchor'></a></span></td><td><span class='out-of-band'></span></td></tr></tbody></table></h3><div class='impl-items'></div></div></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><kbd>?</kbd></dt>
<dd>Show this help dialog</dd>
<dt><kbd>S</kbd></dt>
<dd>Focus the search field</dd>
<dt><kbd></kbd></dt>
<dd>Move up in search results</dd>
<dt><kbd></kbd></dt>
<dd>Move down in search results</dd>
<dt><kbd></kbd></dt>
<dd>Switch tab</dd>
<dt><kbd>&#9166;</kbd></dt>
<dd>Go to active search result</dd>
<dt><kbd>+</kbd></dt>
<dd>Expand all sections</dd>
<dt><kbd>-</kbd></dt>
<dd>Collapse all sections</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 = "tokio";
</script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>