doc update

generated from commit 837c7980e8a5b84be28825303faac0ba28e53446
This commit is contained in:
Harald Hoyer 2018-12-20 16:02:24 +01:00
parent 991a7a0786
commit 188d93a86a
15 changed files with 116 additions and 18 deletions

View file

@ -140,7 +140,7 @@
<div id="content" class="content">
<main>
<a class="header" href="#simple-chained-string-errors" id="simple-chained-string-errors"><h1>Simple Chained String Errors</h1></a>
<a class="header" href="#simple-chained-string-errors" id="simple-chained-string-errors"><h2>Simple Chained String Errors</h2></a>
<p>Now with the help of the <code>chainerror</code> crate, we can have a nicer output.</p>
<p>Press the play button in the upper right corner and see the nice debug output.</p>
<pre><pre class="playpen"><code class="language-rust">use crate::chainerror::*;
@ -449,6 +449,18 @@ fn main() -&gt; Result&lt;(), Box&lt;Error&gt;&gt; {
# }
# }
</code></pre></pre>
<a class="header" href="#what-did-we-do-here" id="what-did-we-do-here"><h3>What did we do here?</h3></a>
<pre><code class="language-rust ignore"> if let Err(e) = do_some_io() {
Err(cherr!(e, &quot;func2 error&quot;))?;
}
</code></pre>
<p>The macro <code>cherr!(cause, newerror)</code> stores <code>cause</code> as the source/cause of <code>newerror</code> and returns
<code>newerror</code>, along with the filename (<code>file!()</code>) and line number (<code>line!()</code>).</p>
<p><code>Err(e)?</code> then returns the error <code>e</code> applying <code>e.into()</code>, so that we
again have a <code>Err(Box&lt;Error&gt;)</code> as a result.</p>
<p>The <code>Debug</code> implementation of <code>ChainError&lt;T&gt;</code> (which is returned by <code>cherr!()</code>)
prints the <code>Debug</code> of <code>T</code> prefixed with the stored filename and line number.</p>
<p><code>ChainError&lt;T&gt;</code> is in our case <code>ChainError&lt;String&gt;</code>.</p>
</main>