trait.UnsafeNotify.html 11 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!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 `UnsafeNotify` trait in crate `futures`."><meta name="keywords" content="rust, rustlang, rust-lang, UnsafeNotify"><title>futures::executor::UnsafeNotify - 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 trait"><!--[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'>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></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"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><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'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/futures/task_impl/mod.rs.html#530-572' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust trait'>pub unsafe trait UnsafeNotify: <a class="trait" href="../../futures/executor/trait.Notify.html" title="trait futures::executor::Notify">Notify</a> {
  2. 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>;
  3. <div class='item-spacer'></div> unsafe fn <a href='#tymethod.drop_raw' class='fnname'>drop_raw</a>(&amp;self);
  4. }</pre></div><div class='docblock'><p>An unsafe trait for implementing custom forms of memory management behind a
  5. <code>Task</code>.</p>
  6. <p>The <code>futures</code> critically relies on &quot;notification handles&quot; to extract for
  7. futures to contain and then later inform that they're ready to make
  8. progress. These handles, however, must be cheap to create and cheap
  9. to clone to ensure that this operation is efficient throughout the
  10. execution of a program.</p>
  11. <p>Typically this sort of memory management is done in the standard library
  12. with the <code>Arc</code> type. An <code>Arc</code> is relatively cheap to allocate an is
  13. quite cheap to clone and pass around. Plus, it's 100% safe!</p>
  14. <p>When working outside the standard library, however, you don't always have
  15. and <code>Arc</code> type available to you. This trait, <code>UnsafeNotify</code>, is intended
  16. to be the &quot;unsafe version&quot; of the <code>Notify</code> trait. This trait encodes the
  17. memory management operations of a <code>Task</code>'s notification handle, allowing
  18. custom implementations for the memory management of a notification handle.</p>
  19. <p>Put another way, the core notification type in this library,
  20. <code>NotifyHandle</code>, simply internally contains an instance of
  21. <code>*mut UnsafeNotify</code>. This &quot;unsafe trait object&quot; is then used exclusively
  22. to operate with, dynamically dispatching calls to clone, drop, and notify.
  23. Critically though as a raw pointer it doesn't require a particular form
  24. of memory management, allowing external implementations.</p>
  25. <p>A default implementation of the <code>UnsafeNotify</code> trait is provided for the
  26. <code>Arc</code> type in the standard library. If the <code>use_std</code> feature of this crate
  27. is not available however, you'll be required to implement your own
  28. instance of this trait to pass it into <code>NotifyHandle::new</code>.</p>
  29. <h1 id="unsafety" class="section-header"><a href="#unsafety">Unsafety</a></h1>
  30. <p>This trait is manually encoding the memory management of the underlying
  31. handle, and as a result is quite unsafe to implement! Implementors of
  32. this trait must guarantee:</p>
  33. <ul>
  34. <li>Calls to <code>clone_raw</code> produce uniquely owned handles. It should be safe
  35. to drop the current handle and have the returned handle still be valid.</li>
  36. <li>Calls to <code>drop_raw</code> work with <code>self</code> as a raw pointer, deallocating
  37. resources associated with it. This is a pretty unsafe operation as it's
  38. invalidating the <code>self</code> pointer, so extreme care needs to be taken.</li>
  39. </ul>
  40. <p>In general it's recommended to review the trait documentation as well as
  41. the implementation for <code>Arc</code> in this crate. When in doubt ping the
  42. <code>futures</code> authors to clarify an unsafety question here.</p>
  43. </div>
  44. <h2 id='required-methods' class='small-section-header'>
  45. Required Methods<a href='#required-methods' class='anchor'></a>
  46. </h2>
  47. <div class='methods'>
  48. <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>
  49. <p>This function will create a new uniquely owned handle that under the
  50. hood references the same notification instance. In other words calls
  51. to <code>notify</code> on the returned handle should be equivalent to calls to
  52. <code>notify</code> on this handle.</p>
  53. <h1 id="unsafety-1" class="section-header"><a href="#unsafety-1">Unsafety</a></h1>
  54. <p>This trait is unsafe to implement, as are all these methods. This
  55. method is also unsafe to call as it's asserting the <code>UnsafeNotify</code>
  56. value is in a consistent state. In general it's recommended to
  57. review the trait documentation as well as the implementation for <code>Arc</code>
  58. in this crate. When in doubt ping the <code>futures</code> authors to clarify
  59. an unsafety question here.</p>
  60. </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
  61. associated with it.</p>
  62. <p>This method is intended to have a signature such as:</p>
  63. <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">
  64. <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>
  65. <p>Unfortunately in Rust today that signature is not object safe.
  66. Nevertheless it's recommended to implement this function <em>as if</em> that
  67. were its signature. As such it is not safe to call on an invalid
  68. pointer, nor is the validity of the pointer guaranteed after this
  69. function returns.</p>
  70. <h1 id="unsafety-2" class="section-header"><a href="#unsafety-2">Unsafety</a></h1>
  71. <p>This trait is unsafe to implement, as are all these methods. This
  72. method is also unsafe to call as it's asserting the <code>UnsafeNotify</code>
  73. value is in a consistent state. In general it's recommended to
  74. review the trait documentation as well as the implementation for <code>Arc</code>
  75. in this crate. When in doubt ping the <code>futures</code> authors to clarify
  76. an unsafety question here.</p>
  77. </div></div>
  78. <h2 id='implementors' class='small-section-header'>
  79. Implementors<a href='#implementors' class='anchor'></a>
  80. </h2>
  81. <ul class='item-list' id='implementors-list'>
  82. </ul><script type="text/javascript">window.inlined_types=new Set([]);</script><script type="text/javascript" async
  83. src="../../implementors/futures/executor/trait.UnsafeNotify.js">
  84. </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><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><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "futures";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>