trait.UnsafeNotify.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 `UnsafeNotify` trait in crate `futures`.">
  8. <meta name="keywords" content="rust, rustlang, rust-lang, UnsafeNotify">
  9. <title>futures::executor::UnsafeNotify - 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 trait">
  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'>Trait UnsafeNotify</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.clone_raw">clone_raw</a><a href="#tymethod.drop_raw">drop_raw</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>futures</a>::<wbr><a href='index.html'>executor</a></p><script>window.sidebarCurrent = {name: 'UnsafeNotify', ty: 'trait', 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'>Trait <a href='../index.html'>futures</a>::<wbr><a href='index.html'>executor</a>::<wbr><a class="trait" href=''>UnsafeNotify</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/futures/task_impl/mod.rs.html#530-572' title='goto source code'>[src]</a></span></h1>
  50. <pre class='rust trait'>pub unsafe trait UnsafeNotify: <a class="trait" href="../../futures/executor/trait.Notify.html" title="trait futures::executor::Notify">Notify</a> {
  51. unsafe fn <a href='#tymethod.clone_raw' class='fnname'>clone_raw</a>(&amp;self) -&gt; <a class="struct" href="../../futures/executor/struct.NotifyHandle.html" title="struct futures::executor::NotifyHandle">NotifyHandle</a>;
  52. <div class='item-spacer'></div> unsafe fn <a href='#tymethod.drop_raw' class='fnname'>drop_raw</a>(&amp;self);
  53. }</pre><div class='docblock'><p>An unsafe trait for implementing custom forms of memory management behind a
  54. <code>Task</code>.</p>
  55. <p>The <code>futures</code> critically relies on &quot;notification handles&quot; to extract for
  56. futures to contain and then later inform that they're ready to make
  57. progress. These handles, however, must be cheap to create and cheap
  58. to clone to ensure that this operation is efficient throughout the
  59. execution of a program.</p>
  60. <p>Typically this sort of memory management is done in the standard library
  61. with the <code>Arc</code> type. An <code>Arc</code> is relatively cheap to allocate an is
  62. quite cheap to clone and pass around. Plus, it's 100% safe!</p>
  63. <p>When working outside the standard library, however, you don't always have
  64. and <code>Arc</code> type available to you. This trait, <code>UnsafeNotify</code>, is intended
  65. to be the &quot;unsafe version&quot; of the <code>Notify</code> trait. This trait encodes the
  66. memory management operations of a <code>Task</code>'s notification handle, allowing
  67. custom implementations for the memory management of a notification handle.</p>
  68. <p>Put another way, the core notification type in this library,
  69. <code>NotifyHandle</code>, simply internally contains an instance of
  70. <code>*mut UnsafeNotify</code>. This &quot;unsafe trait object&quot; is then used exclusively
  71. to operate with, dynamically dispatching calls to clone, drop, and notify.
  72. Critically though as a raw pointer it doesn't require a particular form
  73. of memory management, allowing external implementations.</p>
  74. <p>A default implementation of the <code>UnsafeNotify</code> trait is provided for the
  75. <code>Arc</code> type in the standard library. If the <code>use_std</code> feature of this crate
  76. is not available however, you'll be required to implement your own
  77. instance of this trait to pass it into <code>NotifyHandle::new</code>.</p>
  78. <h1 id="unsafety" class="section-header"><a href="#unsafety">Unsafety</a></h1>
  79. <p>This trait is manually encoding the memory management of the underlying
  80. handle, and as a result is quite unsafe to implement! Implementors of
  81. this trait must guarantee:</p>
  82. <ul>
  83. <li>Calls to <code>clone_raw</code> produce uniquely owned handles. It should be safe
  84. to drop the current handle and have the returned handle still be valid.</li>
  85. <li>Calls to <code>drop_raw</code> work with <code>self</code> as a raw pointer, deallocating
  86. resources associated with it. This is a pretty unsafe operation as it's
  87. invalidating the <code>self</code> pointer, so extreme care needs to be taken.</li>
  88. </ul>
  89. <p>In general it's recommended to review the trait documentation as well as
  90. the implementation for <code>Arc</code> in this crate. When in doubt ping the
  91. <code>futures</code> authors to clarify an unsafety question here.</p>
  92. </div>
  93. <h2 id='required-methods' class='small-section-header'>
  94. Required Methods<a href='#required-methods' class='anchor'></a>
  95. </h2>
  96. <div class='methods'>
  97. <h3 id='tymethod.clone_raw' class='method'><span id='clone_raw.v' class='invisible'><code>unsafe fn <a href='#tymethod.clone_raw' class='fnname'>clone_raw</a>(&amp;self) -&gt; <a class="struct" href="../../futures/executor/struct.NotifyHandle.html" title="struct futures::executor::NotifyHandle">NotifyHandle</a></code></span></h3><div class='docblock'><p>Creates a new <code>NotifyHandle</code> from this instance of <code>UnsafeNotify</code>.</p>
  98. <p>This function will create a new uniquely owned handle that under the
  99. hood references the same notification instance. In other words calls
  100. to <code>notify</code> on the returned handle should be equivalent to calls to
  101. <code>notify</code> on this handle.</p>
  102. <h1 id="unsafety-1" class="section-header"><a href="#unsafety-1">Unsafety</a></h1>
  103. <p>This trait is unsafe to implement, as are all these methods. This
  104. method is also unsafe to call as it's asserting the <code>UnsafeNotify</code>
  105. value is in a consistent state. In general it's recommended to
  106. review the trait documentation as well as the implementation for <code>Arc</code>
  107. in this crate. When in doubt ping the <code>futures</code> authors to clarify
  108. an unsafety question here.</p>
  109. </div><h3 id='tymethod.drop_raw' class='method'><span id='drop_raw.v' class='invisible'><code>unsafe fn <a href='#tymethod.drop_raw' class='fnname'>drop_raw</a>(&amp;self)</code></span></h3><div class='docblock'><p>Drops this instance of <code>UnsafeNotify</code>, deallocating resources
  110. associated with it.</p>
  111. <p>This method is intended to have a signature such as:</p>
  112. <div class='information'><div class='tooltip ignore'>ⓘ<span class='tooltiptext'>This example is not tested</span></div></div><pre class="rust rust-example-rendered ignore">
  113. <span class="kw">fn</span> <span class="ident">drop_raw</span>(<span class="self">self</span>: <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="self">Self</span>);</pre>
  114. <p>Unfortunately in Rust today that signature is not object safe.
  115. Nevertheless it's recommended to implement this function <em>as if</em> that
  116. were its signature. As such it is not safe to call on an invalid
  117. pointer, nor is the validity of the pointer guaranteed after this
  118. function returns.</p>
  119. <h1 id="unsafety-2" class="section-header"><a href="#unsafety-2">Unsafety</a></h1>
  120. <p>This trait is unsafe to implement, as are all these methods. This
  121. method is also unsafe to call as it's asserting the <code>UnsafeNotify</code>
  122. value is in a consistent state. In general it's recommended to
  123. review the trait documentation as well as the implementation for <code>Arc</code>
  124. in this crate. When in doubt ping the <code>futures</code> authors to clarify
  125. an unsafety question here.</p>
  126. </div></div>
  127. <h2 id='implementors' class='small-section-header'>
  128. Implementors<a href='#implementors' class='anchor'></a>
  129. </h2>
  130. <ul class='item-list' id='implementors-list'>
  131. </ul><script type="text/javascript" async
  132. src="../../implementors/futures/executor/trait.UnsafeNotify.js">
  133. </script></section>
  134. <section id='search' class="content hidden"></section>
  135. <section class="footer"></section>
  136. <aside id="help" class="hidden">
  137. <div>
  138. <h1 class="hidden">Help</h1>
  139. <div class="shortcuts">
  140. <h2>Keyboard Shortcuts</h2>
  141. <dl>
  142. <dt><kbd>?</kbd></dt>
  143. <dd>Show this help dialog</dd>
  144. <dt><kbd>S</kbd></dt>
  145. <dd>Focus the search field</dd>
  146. <dt><kbd>↑</kbd></dt>
  147. <dd>Move up in search results</dd>
  148. <dt><kbd>↓</kbd></dt>
  149. <dd>Move down in search results</dd>
  150. <dt><kbd>↹</kbd></dt>
  151. <dd>Switch tab</dd>
  152. <dt><kbd>&#9166;</kbd></dt>
  153. <dd>Go to active search result</dd>
  154. <dt><kbd>+</kbd></dt>
  155. <dd>Expand all sections</dd>
  156. <dt><kbd>-</kbd></dt>
  157. <dd>Collapse all sections</dd>
  158. </dl>
  159. </div>
  160. <div class="infos">
  161. <h2>Search Tricks</h2>
  162. <p>
  163. Prefix searches with a type followed by a colon (e.g.
  164. <code>fn:</code>) to restrict the search to a given type.
  165. </p>
  166. <p>
  167. Accepted types are: <code>fn</code>, <code>mod</code>,
  168. <code>struct</code>, <code>enum</code>,
  169. <code>trait</code>, <code>type</code>, <code>macro</code>,
  170. and <code>const</code>.
  171. </p>
  172. <p>
  173. Search functions by type signature (e.g.
  174. <code>vec -> usize</code> or <code>* -> vec</code>)
  175. </p>
  176. </div>
  177. </div>
  178. </aside>
  179. <script>
  180. window.rootPath = "../../";
  181. window.currentCrate = "futures";
  182. </script>
  183. <script src="../../main.js"></script>
  184. <script defer src="../../search-index.js"></script>
  185. </body>
  186. </html>