struct.SyncFailure.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta name="generator" content="rustdoc">
  7. <meta name="description" content="API documentation for the Rust `SyncFailure` struct in crate `failure`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, SyncFailure">
  9. <title>failure::SyncFailure - Rust</title>
  10. <link rel="stylesheet" type="text/css" href="../normalize.css">
  11. <link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
  12. <link rel="stylesheet" type="text/css" href="../dark.css">
  13. <link rel="stylesheet" type="text/css" href="../main.css" id="themeStyle">
  14. <script src="../storage.js"></script>
  15. </head>
  16. <body class="rustdoc struct">
  17. <!--[if lte IE 8]>
  18. <div class="warning">
  19. This old browser is unsupported and will most likely display funky
  20. things.
  21. </div>
  22. <![endif]-->
  23. <nav class="sidebar">
  24. <div class="sidebar-menu">&#9776;</div>
  25. <p class='location'>Struct SyncFailure</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></div><a class="sidebar-title" href="#implementations">Trait Implementations</a><div class="sidebar-links"><a href="#impl-Display">Display</a><a href="#impl-Debug">Debug</a><a href="#impl-Fail">Fail</a></div></div><p class='location'><a href='index.html'>failure</a></p><script>window.sidebarCurrent = {name: 'SyncFailure', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script></div>
  26. </nav>
  27. <div class="theme-picker">
  28. <button id="theme-picker" aria-label="Pick another theme!">
  29. <img src="../brush.svg" width="18" alt="Pick another theme!">
  30. </button>
  31. <div id="theme-choices"></div>
  32. </div>
  33. <script src="../theme.js"></script>
  34. <nav class="sub">
  35. <form class="search-form js-only">
  36. <div class="search-container">
  37. <input class="search-input" name="search"
  38. autocomplete="off"
  39. placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
  40. type="search">
  41. </div>
  42. </form>
  43. </nav>
  44. <section id='main' class="content">
  45. <h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>failure</a>::<wbr><a class="struct" href=''>SyncFailure</a></span><span class='out-of-band'><span id='render-detail'>
  46. <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
  47. [<span class='inner'>&#x2212;</span>]
  48. </a>
  49. </span><a class='srclink' href='../src/failure/sync_failure.rs.html#16-18' title='goto source code'>[src]</a></span></h1>
  50. <pre class='rust struct'>pub struct SyncFailure&lt;T&gt; { /* fields omitted */ }</pre><div class='docblock'><p>Wrapper for <code>std</code> errors to make them <code>Sync</code>.</p>
  51. <p>This exists to coerce existing types that are only <code>Error + Send + 'static</code> into a <code>Fail</code>-compatible representation, most notably for
  52. types generated by <code>error-chain</code>.</p>
  53. <p>Unfortunately, this requires wrapping the error in a <code>Mutex</code>, which must
  54. be locked for every <code>Debug</code>/<code>Display</code>. Therefore, this should be
  55. something of a last resort in making the error work with <code>failure</code>.</p>
  56. </div>
  57. <h2 id='methods' class='small-section-header'>
  58. Methods<a href='#methods' class='anchor'></a>
  59. </h2>
  60. <h3 id='impl' class='impl'><span class='in-band'><code>impl&lt;E:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static&gt; <a class="struct" href="../failure/struct.SyncFailure.html" title="struct failure::SyncFailure">SyncFailure</a>&lt;E&gt;</code><a href='#impl' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#20-77' title='goto source code'>[src]</a></span></h3>
  61. <div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>pub fn <a href='#method.new' class='fnname'>new</a>(err: E) -&gt; Self</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#72-76' title='goto source code'>[src]</a></span></h4>
  62. <div class='docblock'><p>Wraps a non-<code>Sync</code> <code>Error</code> in order to make it implement <code>Fail</code>.</p>
  63. <h1 id="example" class="section-header"><a href="#example">Example</a></h1>
  64. <pre class="rust rust-example-rendered">
  65. <span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">failure</span>;
  66. <span class="kw">use</span> <span class="ident">failure</span>::{<span class="ident">Error</span>, <span class="ident">SyncFailure</span>};
  67. <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">cell</span>::<span class="ident">RefCell</span>;
  68. <span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Debug</span>)]</span>
  69. <span class="kw">struct</span> <span class="ident">NonSyncError</span> {
  70. <span class="comment">// RefCells are non-Sync, so structs containing them will be</span>
  71. <span class="comment">// non-Sync as well.</span>
  72. <span class="ident">count</span>: <span class="ident">RefCell</span><span class="op">&lt;</span><span class="ident">usize</span><span class="op">&gt;</span>,
  73. }
  74. <span class="comment">// implement Display/Error for NonSyncError...</span>
  75. <span class="kw">fn</span> <span class="ident">returns_error</span>() <span class="op">-&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">NonSyncError</span><span class="op">&gt;</span> {
  76. <span class="comment">// Do stuff</span>
  77. }
  78. <span class="kw">fn</span> <span class="ident">my_function</span>() <span class="op">-&gt;</span> <span class="prelude-ty">Result</span><span class="op">&lt;</span>(), <span class="ident">Error</span><span class="op">&gt;</span> {
  79. <span class="comment">// without the map_err here, we end up with a compile error</span>
  80. <span class="comment">// complaining that NonSyncError doesn&#39;t implement Sync.</span>
  81. <span class="ident">returns_error</span>().<span class="ident">map_err</span>(<span class="ident">SyncFailure</span>::<span class="ident">new</span>)<span class="question-mark">?</span>;
  82. <span class="comment">// Do more stuff</span>
  83. }</pre>
  84. </div></div>
  85. <h2 id='implementations' class='small-section-header'>
  86. Trait Implementations<a href='#implementations' class='anchor'></a>
  87. </h2>
  88. <h3 id='impl-Display' class='impl'><span class='in-band'><code>impl&lt;T&gt; <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="../failure/struct.SyncFailure.html" title="struct failure::SyncFailure">SyncFailure</a>&lt;T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>,&nbsp;</span></code><a href='#impl-Display' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#79-86' title='goto source code'>[src]</a></span></h3>
  89. <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='https://doc.rust-lang.org/nightly/core/fmt/trait.Display.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="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#83-85' title='goto source code'>[src]</a></span></h4>
  90. <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>
  91. </div></div><h3 id='impl-Debug' class='impl'><span class='in-band'><code>impl&lt;T&gt; <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="../failure/struct.SyncFailure.html" title="struct failure::SyncFailure">SyncFailure</a>&lt;T&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>,&nbsp;</span></code><a href='#impl-Debug' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#88-95' title='goto source code'>[src]</a></span></h3>
  92. <div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><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="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#92-94' title='goto source code'>[src]</a></span></h4>
  93. <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>
  94. </div></div><h3 id='impl-Fail' class='impl'><span class='in-band'><code>impl&lt;E:&nbsp;<a class="trait" href="https://doc.rust-lang.org/nightly/std/error/trait.Error.html" title="trait std::error::Error">Error</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + 'static&gt; <a class="trait" href="../failure/trait.Fail.html" title="trait failure::Fail">Fail</a> for <a class="struct" href="../failure/struct.SyncFailure.html" title="struct failure::SyncFailure">SyncFailure</a>&lt;E&gt;</code><a href='#impl-Fail' class='anchor'></a></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/sync_failure.rs.html#97' title='goto source code'>[src]</a></span></h3>
  95. <div class='impl-items'><h4 id='method.cause' class="method"><span id='cause.v' class='invisible'><code>fn <a href='../failure/trait.Fail.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="../failure/trait.Fail.html" title="trait failure::Fail">Fail</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/lib.rs.html#97-99' title='goto source code'>[src]</a></span></h4>
  96. <div class='docblock'><p>Returns a reference to the underlying cause of this failure, if it is an error that wraps other errors. <a href="../failure/trait.Fail.html#method.cause">Read more</a></p>
  97. </div><h4 id='method.backtrace' class="method"><span id='backtrace.v' class='invisible'><code>fn <a href='../failure/trait.Fail.html#method.backtrace' class='fnname'>backtrace</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="struct" href="../failure/struct.Backtrace.html" title="struct failure::Backtrace">Backtrace</a>&gt;</code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/lib.rs.html#106-108' title='goto source code'>[src]</a></span></h4>
  98. <div class='docblock'><p>Returns a reference to the <code>Backtrace</code> carried by this failure, if it carries one. <a href="../failure/trait.Fail.html#method.backtrace">Read more</a></p>
  99. </div><h4 id='method.context' class="method"><span id='context.v' class='invisible'><code>fn <a href='../failure/trait.Fail.html#method.context' class='fnname'>context</a>&lt;D&gt;(self, context: D) -&gt; <a class="struct" href="../failure/struct.Context.html" title="struct failure::Context">Context</a>&lt;D&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;D: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> + 'static,<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/lib.rs.html#123-128' title='goto source code'>[src]</a></span></h4>
  100. <div class='docblock'><p>Provides context for this failure. <a href="../failure/trait.Fail.html#method.context">Read more</a></p>
  101. </div><h4 id='method.compat' class="method"><span id='compat.v' class='invisible'><code>fn <a href='../failure/trait.Fail.html#method.compat' class='fnname'>compat</a>(self) -&gt; <a class="struct" href="../failure/struct.Compat.html" title="struct failure::Compat">Compat</a>&lt;Self&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/lib.rs.html#135-139' title='goto source code'>[src]</a></span></h4>
  102. <div class='docblock'><p>Wraps this failure in a compatibility wrapper that implements <code>std::error::Error</code>. <a href="../failure/trait.Fail.html#method.compat">Read more</a></p>
  103. </div><h4 id='method.causes' class="method"><div class="important-traits"><div class='tooltip'>ⓘ<span class='tooltiptext'>Important traits for <a class="struct" href="../failure/struct.Causes.html" title="struct failure::Causes">Causes</a>&lt;'f&gt;</span></div><div class="content hidden"><h3 class="important">Important traits for <a class="struct" href="../failure/struct.Causes.html" title="struct failure::Causes">Causes</a>&lt;'f&gt;</h3><code class="content"><span class="where fmt-newline">impl&lt;'f&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html" title="trait core::iter::iterator::Iterator">Iterator</a> for <a class="struct" href="../failure/struct.Causes.html" title="struct failure::Causes">Causes</a>&lt;'f&gt;</span><span class="where fmt-newline"> type <a href='https://doc.rust-lang.org/nightly/core/iter/iterator/trait.Iterator.html#associatedtype.Item' class="type">Item</a> = &amp;'f <a class="trait" href="../failure/trait.Fail.html" title="trait failure::Fail">Fail</a>;</span></code></div></div><span id='causes.v' class='invisible'><code>fn <a href='../failure/trait.Fail.html#method.causes' class='fnname'>causes</a>(&amp;self) -&gt; <a class="struct" href="../failure/struct.Causes.html" title="struct failure::Causes">Causes</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/lib.rs.html#143-145' title='goto source code'>[src]</a></span></h4>
  104. <div class='docblock'><p>Returns a iterator over the causes of this <code>Fail</code> with itself as the first item and the <code>root_cause</code> as the final item. <a href="../failure/trait.Fail.html#method.causes">Read more</a></p>
  105. </div><h4 id='method.root_cause' class="method"><span id='root_cause.v' class='invisible'><code>fn <a href='../failure/trait.Fail.html#method.root_cause' class='fnname'>root_cause</a>(&amp;self) -&gt; &amp;<a class="trait" href="../failure/trait.Fail.html" title="trait failure::Fail">Fail</a> <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../src/failure/lib.rs.html#152-156' title='goto source code'>[src]</a></span></h4>
  106. <div class='docblock'><p>Returns the &quot;root cause&quot; of this <code>Fail</code> - the last value in the cause chain which does not return an underlying <code>cause</code>. <a href="../failure/trait.Fail.html#method.root_cause">Read more</a></p>
  107. </div></div></section>
  108. <section id='search' class="content hidden"></section>
  109. <section class="footer"></section>
  110. <aside id="help" class="hidden">
  111. <div>
  112. <h1 class="hidden">Help</h1>
  113. <div class="shortcuts">
  114. <h2>Keyboard Shortcuts</h2>
  115. <dl>
  116. <dt><kbd>?</kbd></dt>
  117. <dd>Show this help dialog</dd>
  118. <dt><kbd>S</kbd></dt>
  119. <dd>Focus the search field</dd>
  120. <dt><kbd>↑</kbd></dt>
  121. <dd>Move up in search results</dd>
  122. <dt><kbd>↓</kbd></dt>
  123. <dd>Move down in search results</dd>
  124. <dt><kbd>↹</kbd></dt>
  125. <dd>Switch tab</dd>
  126. <dt><kbd>&#9166;</kbd></dt>
  127. <dd>Go to active search result</dd>
  128. <dt><kbd>+</kbd></dt>
  129. <dd>Expand all sections</dd>
  130. <dt><kbd>-</kbd></dt>
  131. <dd>Collapse all sections</dd>
  132. </dl>
  133. </div>
  134. <div class="infos">
  135. <h2>Search Tricks</h2>
  136. <p>
  137. Prefix searches with a type followed by a colon (e.g.
  138. <code>fn:</code>) to restrict the search to a given type.
  139. </p>
  140. <p>
  141. Accepted types are: <code>fn</code>, <code>mod</code>,
  142. <code>struct</code>, <code>enum</code>,
  143. <code>trait</code>, <code>type</code>, <code>macro</code>,
  144. and <code>const</code>.
  145. </p>
  146. <p>
  147. Search functions by type signature (e.g.
  148. <code>vec -> usize</code> or <code>* -> vec</code>)
  149. </p>
  150. </div>
  151. </div>
  152. </aside>
  153. <script>
  154. window.rootPath = "../";
  155. window.currentCrate = "failure";
  156. </script>
  157. <script src="../main.js"></script>
  158. <script defer src="../search-index.js"></script>
  159. </body>
  160. </html>