<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="List of all items in this crate"><metaname="keywords"content="rust, rustlang, rust-lang"><title>List of all items in this crate</title><linkrel="stylesheet"type="text/css"href="../normalize.css"><linkrel="stylesheet"type="text/css"href="../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../light.css"id="themeStyle"><linkrel="stylesheet"type="text/css"href="../dark.css"disabled><linkrel="stylesheet"type="text/css"href="../ayu.css"disabled><scriptid="default-settings"></script><scriptsrc="../storage.js"></script><noscript><linkrel="stylesheet"href="../noscript.css"></noscript><linkrel="icon"type="image/svg+xml"href="../favicon.svg">
<linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><styletype="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><bodyclass="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><ahref='../pin_project/index.html'><divclass='logo-container rust-logo'><imgsrc='../rust-logo.png'alt='logo'></div></a><pclass="location">Crate pin_project</p><divclass="block version"><p>Version 1.0.5</p></div><aid="all-types"href="index.html"><p>Back to index</p></a></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"><imgsrc="../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"role="menu"></div></div><scriptsrc="../theme.js"></script><navclass="sub"><formclass="search-form"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"disabledautocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><buttontype="button"class="help-button">?</button>
<aid="settings-menu"href="../settings.html"><imgsrc="../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class="fqn"><spanclass="in-band">List of all items</span><spanclass="out-of-band"><spanid="render-detail"><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass="inner">−</span>]</a></span>
</span>
<spanclass="in-band">List of all items</span></h1><h3id="Traits">Traits</h3><ulclass="traits docblock"><li><ahref="trait.UnsafeUnpin.html">UnsafeUnpin</a></li></ul><h3id="Attribute Macros">Attribute Macros</h3><ulclass="attributes docblock"><li><ahref="attr.pin_project.html">pin_project</a></li><li><ahref="attr.pinned_drop.html">pinned_drop</a></li></ul></section><sectionid="search"class="content hidden"></section><sectionclass="footer"></section><divid="rustdoc-vars"data-root-path="../"data-current-crate="pin_project"></div>
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="An attribute that creates projection types covering all the fields of struct or enum."><metaname="keywords"content="rust, rustlang, rust-lang, pin_project"><title>pin_project::pin_project - Rust</title><linkrel="stylesheet"type="text/css"href="../normalize.css"><linkrel="stylesheet"type="text/css"href="../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../light.css"id="themeStyle"><linkrel="stylesheet"type="text/css"href="../dark.css"disabled><linkrel="stylesheet"type="text/css"href="../ayu.css"disabled><scriptid="default-settings"></script><scriptsrc="../storage.js"></script><noscript><linkrel="stylesheet"href="../noscript.css"></noscript><linkrel="icon"type="image/svg+xml"href="../favicon.svg">
<linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><styletype="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><bodyclass="rustdoc attr"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><ahref='../pin_project/index.html'><divclass='logo-container rust-logo'><imgsrc='../rust-logo.png'alt='logo'></div></a><divclass="sidebar-elems"><pclass="location"><ahref="index.html">pin_project</a></p><divid="sidebar-vars"data-name="pin_project"data-ty="attr"data-relpath=""></div><scriptdefersrc="sidebar-items.js"></script></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"><imgsrc="../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"role="menu"></div></div><scriptsrc="../theme.js"></script><navclass="sub"><formclass="search-form"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"disabledautocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><buttontype="button"class="help-button">?</button>
<aid="settings-menu"href="../settings.html"><imgsrc="../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class="fqn"><spanclass="in-band">Attribute Macro <ahref="index.html">pin_project</a>::<wbr><aclass="attr"href="">pin_project</a></span><spanclass="out-of-band"><spanid="render-detail"><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass="inner">−</span>]</a></span><aclass="srclink"href="../src/pin_project_internal/lib.rs.html#486"title="goto source code">[src]</a></span></h1><preclass="rust attr">#[pin_project]</pre><divclass="docblock"><p>An attribute that creates projection types covering all the fields of
struct or enum.</p>
<p>This attribute creates projection types according to the following rules:</p>
<ul>
<li>For the fields that use <code>#[pin]</code> attribute, create the pinned reference to
the field.</li>
<li>For the other fields, create a normal reference to the field.</li>
</ul>
<p>And the following methods are implemented on the original type:</p>
<p>This attribute is completely safe. In the absence of other <code>unsafe</code> code
<em>that you write</em>, it is impossible to cause <ahref="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">undefined
behavior</a> with this attribute.</p>
<p>This is accomplished by enforcing the four requirements for pin projection
stated in <ahref="https://doc.rust-lang.org/nightly/core/pin/index.html#projections-and-structural-pinning">the Rust documentation</a>:</p>
<ol>
<li>
<p>The struct must only be <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> if all the structural fields are
<p>To enforce this, this attribute will automatically generate an <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>
implementation for you, which will require that all structurally pinned
fields be <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>.</p>
<p>If you attempt to provide an <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> impl, the blanket impl will then
apply to your type, causing a compile-time error due to the conflict with
the second impl.</p>
<p>If you wish to provide a manual <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> impl, you can do so via the
<p>If you attempt to provide an <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl, the blanket impl will then
apply to your type, causing a compile-time error due to the conflict with
the second impl.</p>
<p>If you wish to provide a custom <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl, you can annotate an impl
with <ahref="../pin_project/attr.pin_project.html#pinned_drop"><code>#[pinned_drop]</code></a>. This impl takes a pinned version of
your struct - that is, <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html"><code>Pin</code></a><code><&mut MyStruct></code> where <code>MyStruct</code> is the
type of your struct.</p>
<p>You can call <code>.project()</code> on this type as usual, along with any other
methods you have defined. Because your code is never provided with
a <code>&mut MyStruct</code>, it is impossible to move out of pin-projectable
fields in safe code in your destructor.</p>
</li>
<li>
<p>You must make sure that you uphold the <ahref="https://doc.rust-lang.org/nightly/core/pin/index.html#drop-guarantee"><code>Drop</code>
guarantee</a>: once your struct is pinned, the memory that
contains the content is not overwritten or deallocated without calling
the content’s destructors.</p>
<p>Safe code doesn’t need to worry about this - the only way to violate
this requirement is to manually deallocate memory (which is <code>unsafe</code>),
or to overwrite a field with something else.
Because your custom destructor takes <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html"><code>Pin</code></a><code><&mut MyStruct></code>, it’s
impossible to obtain a mutable reference to a pin-projected field in safe
code.</p>
</li>
<li>
<p>You must not offer any other operations that could lead to data being
moved out of the structural fields when your type is pinned.</p>
<p>As with requirement 3, it is impossible for safe code to violate this.
This crate ensures that safe code can never obtain a mutable reference to
<code>#[pin]</code> fields, which prevents you from ever moving out of them in safe
code.</p>
</li>
</ol>
<p>Pin projections are also incompatible with <ahref="https://doc.rust-lang.org/nomicon/other-reprs.html#reprpacked"><code>#[repr(packed)]</code></a>
types. Attempting to use this attribute on a <code>#[repr(packed)]</code> type results
<spanclass="comment">//~^ ERROR no method named `project_ref` found for struct `Pin<&Enum<T, U>>` in the current scope</span>
}
}</pre></div>
<p>If you want to call <code>.project()</code> multiple times or later use the
original <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html"><code>Pin</code></a> type, it needs to use <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html#method.as_mut"><code>.as_mut()</code></a> to avoid
consuming the <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html"><code>Pin</code></a>.</p>
<p>If you want to ensure that <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> is not implemented, use the <code>!Unpin</code>
<p>This is equivalent to using <code>#[pin]</code> attribute for the <ahref="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomPinned.html"><code>PhantomPinned</code></a>
<spanclass="attribute">#[<spanclass="ident">pin</span>]</span><spanclass="comment">// <------ This `#[pin]` is required to make `Struct` to `!Unpin`.</span>
<p>Note that using <ahref="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomPinned.html"><code>PhantomPinned</code></a> without <code>#[pin]</code> attribute has no effect.</p>
<p>If you want to implement <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> manually, you must use the <code>UnsafeUnpin</code>
<p>Note the usage of the unsafe <ahref="https://docs.rs/pin-project/1/pin_project/trait.UnsafeUnpin.html"><code>UnsafeUnpin</code></a> trait, instead of the usual
<ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> trait. <ahref="https://docs.rs/pin-project/1/pin_project/trait.UnsafeUnpin.html"><code>UnsafeUnpin</code></a> behaves exactly like <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>, except that
is unsafe to implement. This unsafety comes from the fact that pin
projections are being used. If you implement <ahref="https://docs.rs/pin-project/1/pin_project/trait.UnsafeUnpin.html"><code>UnsafeUnpin</code></a>, you must
ensure that it is only implemented when all pin-projected fields implement
<p>In order to correctly implement pin projections, a type’s <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl must
not move out of any structurally pinned fields. Unfortunately,
<ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html#tymethod.drop"title="Drop::drop"><code>Drop::drop</code></a> takes <code>&mut Self</code>, not <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html"><code>Pin</code></a><code><&mut Self></code>.</p>
<p>To ensure that this requirement is upheld, the <code>#[pin_project]</code> attribute
will provide a <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl for you. This <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl will delegate to
an impl block annotated with <code>#[pinned_drop]</code> if you use the <code>PinnedDrop</code>
argument to <code>#[pin_project]</code>.</p>
<p>This impl block acts just like a normal <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl,
<p><code>#[pin_project]</code> implements the actual <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> trait via <code>PinnedDrop</code> you
implemented. To drop a type that implements <code>PinnedDrop</code>, use the <ahref="https://doc.rust-lang.org/nightly/core/mem/fn.drop.html"title="drop"><code>drop</code></a>
function just like dropping a type that directly implements <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a>.</p>
<p>In particular, it will never be called more than once, just like
<p>In addition to the <code>project</code> and <code>project_ref</code> methods which are always
provided when you use the <code>#[pin_project]</code> attribute, there is a third
method, <code>project_replace</code> which can be useful in some situations. It is
equivalent to <ahref="https://doc.rust-lang.org/nightly/core/pin/struct.Pin.html#method.set"><code>Pin::set</code></a>, except that the unpinned fields are moved and
<p>The <code>ProjectionOwned</code> type is identical to the <code>Self</code> type, except that
all pinned fields have been replaced by equivalent <ahref="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomData.html"><code>PhantomData</code></a> types.</p>
<p>This method is opt-in, because it is only supported for <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html"title="Sized"><code>Sized</code></a> types, and
because it is incompatible with the <ahref="../pin_project/attr.pin_project.html#pinned_drop"><code>#[pinned_drop]</code></a>
attribute described above. It can be enabled by using
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="An attribute used for custom implementations of [`Drop`]."><metaname="keywords"content="rust, rustlang, rust-lang, pinned_drop"><title>pin_project::pinned_drop - Rust</title><linkrel="stylesheet"type="text/css"href="../normalize.css"><linkrel="stylesheet"type="text/css"href="../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../light.css"id="themeStyle"><linkrel="stylesheet"type="text/css"href="../dark.css"disabled><linkrel="stylesheet"type="text/css"href="../ayu.css"disabled><scriptid="default-settings"></script><scriptsrc="../storage.js"></script><noscript><linkrel="stylesheet"href="../noscript.css"></noscript><linkrel="icon"type="image/svg+xml"href="../favicon.svg">
<linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><styletype="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><bodyclass="rustdoc attr"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><ahref='../pin_project/index.html'><divclass='logo-container rust-logo'><imgsrc='../rust-logo.png'alt='logo'></div></a><divclass="sidebar-elems"><pclass="location"><ahref="index.html">pin_project</a></p><divid="sidebar-vars"data-name="pinned_drop"data-ty="attr"data-relpath=""></div><scriptdefersrc="sidebar-items.js"></script></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"><imgsrc="../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"role="menu"></div></div><scriptsrc="../theme.js"></script><navclass="sub"><formclass="search-form"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"disabledautocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><buttontype="button"class="help-button">?</button>
<aid="settings-menu"href="../settings.html"><imgsrc="../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class="fqn"><spanclass="in-band">Attribute Macro <ahref="index.html">pin_project</a>::<wbr><aclass="attr"href="">pinned_drop</a></span><spanclass="out-of-band"><spanid="render-detail"><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass="inner">−</span>]</a></span><aclass="srclink"href="../src/pin_project_internal/lib.rs.html#568"title="goto source code">[src]</a></span></h1><preclass="rust attr">#[pinned_drop]</pre><divclass="docblock"><p>An attribute used for custom implementations of <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a>.</p>
<p>This attribute is used in conjunction with the <code>PinnedDrop</code> argument to
the <ahref="../pin_project/attr.pin_project.html"title="pin_project"><code>#[pin_project]</code></a> attribute.</p>
<p>The impl block annotated with this attribute acts just like a normal
<ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> impl, except for the following two:</p>
<p><code>#[pin_project]</code> implements the actual <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> trait via <code>PinnedDrop</code> you
implemented. To drop a type that implements <code>PinnedDrop</code>, use the <ahref="https://doc.rust-lang.org/nightly/core/mem/fn.drop.html"title="drop"><code>drop</code></a>
function just like dropping a type that directly implements <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a>.</p>
<p>In particular, it will never be called more than once, just like
<p>See also <ahref="../pin_project/attr.pin_project.html#pinned_drop">“pinned-drop” section of <code>#[pin_project]</code> attribute</a>.</p>
<h1id="why-pinned_drop-attribute-is-needed"class="section-header"><ahref="#why-pinned_drop-attribute-is-needed">Why <code>#[pinned_drop]</code> attribute is needed?</a></h1>
<p>Implementing <code>PinnedDrop::drop</code> is safe, but calling it is not safe.
This is because destructors can be called multiple times in safe code and
<ahref="https://github.com/rust-lang/rust/pull/62360">double dropping is unsound</a>.</p>
<p>Ideally, it would be desirable to be able to forbid manual calls in
the same way as <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html#tymethod.drop"title="Drop::drop"><code>Drop::drop</code></a>, but the library cannot do it. So, by using
macros and replacing them with private traits like the following,
this crate prevent users from calling <code>PinnedDrop::drop</code> in safe code.</p>
<p>This allows implementing <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a> safely using <code>#[pinned_drop]</code>.
Also by using the <ahref="https://doc.rust-lang.org/nightly/core/mem/fn.drop.html"title="drop"><code>drop</code></a> function just like dropping a type that directly
implements <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a>, can drop safely a type that implements <code>PinnedDrop</code>.</p>
<linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><styletype="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><bodyclass="rustdoc mod"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><ahref='../pin_project/index.html'><divclass='logo-container rust-logo'><imgsrc='../rust-logo.png'alt='logo'></div></a><pclass="location">Crate pin_project</p><divclass="block version"><p>Version 1.0.5</p></div><divclass="sidebar-elems"><aid="all-types"href="all.html"><p>See all pin_project's items</p></a><divclass="block items"><ul><li><ahref="#traits">Traits</a></li></ul></div><pclass="location"></p><divid="sidebar-vars"data-name="pin_project"data-ty="mod"data-relpath="../"></div></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"><imgsrc="../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"role="menu"></div></div><scriptsrc="../theme.js"></script><navclass="sub"><formclass="search-form"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"disabledautocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><buttontype="button"class="help-button">?</button>
<aid="settings-menu"href="../settings.html"><imgsrc="../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class="fqn"><spanclass="in-band">Crate <aclass="mod"href="">pin_project</a></span><spanclass="out-of-band"><spanid="render-detail"><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass="inner">−</span>]</a></span><aclass="srclink"href="../src/pin_project/lib.rs.html#1-282"title="goto source code">[src]</a></span></h1><divclass="docblock"><p>A crate for safe and ergonomic <ahref="https://doc.rust-lang.org/nightly/core/pin/index.html#projections-and-structural-pinning">pin-projection</a>.</p>
<spanclass="kw">let</span><spanclass="kw">_</span>: <spanclass="ident">Pin</span><spanclass="op"><</span><spanclass="kw-2">&</span><spanclass="kw-2">mut</span><spanclass="ident">T</span><spanclass="op">></span><spanclass="op">=</span><spanclass="ident">this</span>.<spanclass="ident">pinned</span>; <spanclass="comment">// Pinned reference to the field</span>
<spanclass="kw">let</span><spanclass="kw">_</span>: <spanclass="kw-2">&</span><spanclass="kw-2">mut</span><spanclass="ident">U</span><spanclass="op">=</span><spanclass="ident">this</span>.<spanclass="ident">unpinned</span>; <spanclass="comment">// Normal reference to the field</span>
}
}</pre></div>
<p><ahref="https://github.com/taiki-e/pin-project/blob/master/examples/struct-default-expanded.rs"><em>code like this will be generated</em></a></p>
<p>To use <code>#[pin_project]</code> on enums, you need to name the projection type
<table><trclass="module-item"><td><aclass="trait"href="trait.UnsafeUnpin.html"title="pin_project::UnsafeUnpin trait">UnsafeUnpin</a></td><tdclass="docblock-short"><p>A trait used for custom implementations of <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>.</p>
<table><trclass="module-item"><td><aclass="attr"href="attr.pin_project.html"title="pin_project::pin_project attr">pin_project</a></td><tdclass="docblock-short"><p>An attribute that creates projection types covering all the fields of
struct or enum.</p>
</td></tr><trclass="module-item"><td><aclass="attr"href="attr.pinned_drop.html"title="pin_project::pinned_drop attr">pinned_drop</a></td><tdclass="docblock-short"><p>An attribute used for custom implementations of <ahref="https://doc.rust-lang.org/nightly/core/ops/drop/trait.Drop.html"title="Drop"><code>Drop</code></a>.</p>
initSidebarItems({"attr":[["pin_project","An attribute that creates projection types covering all the fields of struct or enum."],["pinned_drop","An attribute used for custom implementations of [`Drop`]."]],"trait":[["UnsafeUnpin","A trait used for custom implementations of [`Unpin`]."]]});
<!DOCTYPE html><htmllang="en"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metaname="generator"content="rustdoc"><metaname="description"content="A trait used for custom implementations of [`Unpin`]."><metaname="keywords"content="rust, rustlang, rust-lang, UnsafeUnpin"><title>pin_project::UnsafeUnpin - Rust</title><linkrel="stylesheet"type="text/css"href="../normalize.css"><linkrel="stylesheet"type="text/css"href="../rustdoc.css"id="mainThemeStyle"><linkrel="stylesheet"type="text/css"href="../light.css"id="themeStyle"><linkrel="stylesheet"type="text/css"href="../dark.css"disabled><linkrel="stylesheet"type="text/css"href="../ayu.css"disabled><scriptid="default-settings"></script><scriptsrc="../storage.js"></script><noscript><linkrel="stylesheet"href="../noscript.css"></noscript><linkrel="icon"type="image/svg+xml"href="../favicon.svg">
<linkrel="alternate icon"type="image/png"href="../favicon-32x32.png"><styletype="text/css">#crate-search{background-image:url("../down-arrow.svg");}</style></head><bodyclass="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><navclass="sidebar"><divclass="sidebar-menu">☰</div><ahref='../pin_project/index.html'><divclass='logo-container rust-logo'><imgsrc='../rust-logo.png'alt='logo'></div></a><pclass="location">Trait UnsafeUnpin</p><divclass="sidebar-elems"><divclass="block items"><aclass="sidebar-title"href="#implementors">Implementors</a></div><pclass="location"><ahref="index.html">pin_project</a></p><divid="sidebar-vars"data-name="UnsafeUnpin"data-ty="trait"data-relpath=""></div><scriptdefersrc="sidebar-items.js"></script></div></nav><divclass="theme-picker"><buttonid="theme-picker"aria-label="Pick another theme!"aria-haspopup="menu"><imgsrc="../brush.svg"width="18"alt="Pick another theme!"></button><divid="theme-choices"role="menu"></div></div><scriptsrc="../theme.js"></script><navclass="sub"><formclass="search-form"><divclass="search-container"><div><selectid="crate-search"><optionvalue="All crates">All crates</option></select><inputclass="search-input"name="search"disabledautocomplete="off"spellcheck="false"placeholder="Click or press ‘S’ to search, ‘?’ for more options…"type="search"></div><buttontype="button"class="help-button">?</button>
<aid="settings-menu"href="../settings.html"><imgsrc="../wheel.svg"width="18"alt="Change settings"></a></div></form></nav><sectionid="main"class="content"><h1class="fqn"><spanclass="in-band">Trait <ahref="index.html">pin_project</a>::<wbr><aclass="trait"href="">UnsafeUnpin</a></span><spanclass="out-of-band"><spanid="render-detail"><aid="toggle-all-docs"href="javascript:void(0)"title="collapse all docs">[<spanclass="inner">−</span>]</a></span><aclass="srclink"href="../src/pin_project/lib.rs.html#145"title="goto source code">[src]</a></span></h1><divclass="docblock type-decl hidden-by-usual-hider"><preclass="rust trait">pub unsafe trait UnsafeUnpin { }</pre></div><divclass="docblock"><p>A trait used for custom implementations of <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>.</p>
<p>This trait is used in conjunction with the <code>UnsafeUnpin</code> argument to
the <ahref="../pin_project/attr.pin_project.html"title="pin_project"><code>#[pin_project]</code></a> attribute.</p>
<p>The Rust <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> trait is safe to implement - by itself,
implementing it cannot lead to <ahref="https://doc.rust-lang.org/reference/behavior-considered-undefined.html">undefined behavior</a>.
Undefined behavior can only occur when other unsafe code is used.</p>
<p>It turns out that using pin projections, which requires unsafe code,
imposes additional requirements on an <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> impl. Normally, all of this
unsafety is contained within this crate, ensuring that it’s impossible for
you to violate any of the guarantees required by pin projection.</p>
<p>However, things change if you want to provide a custom <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> impl
for your <code>#[pin_project]</code> type. As stated in <ahref="https://doc.rust-lang.org/nightly/core/pin/index.html#projections-and-structural-pinning">the Rust
documentation</a>, you must be sure to only implement <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>
when all of your <code>#[pin]</code> fields (i.e. structurally pinned fields) are also
<p>To help highlight this unsafety, the <code>UnsafeUnpin</code> trait is provided.
Implementing this trait is logically equivalent to implementing <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> -
this crate will generate an <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> impl for your type that ‘forwards’ to
your <code>UnsafeUnpin</code> impl. However, this trait is <code>unsafe</code> - since your type
uses structural pinning (otherwise, you wouldn’t be using this crate!),
you must be sure that your <code>UnsafeUnpin</code> impls follows all of
the requirements for an <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a> impl of a structurally-pinned type.</p>
<p>Note that if you specify <code>#[pin_project(UnsafeUnpin)]</code>, but do <em>not</em>
provide an impl of <code>UnsafeUnpin</code>, your type will never implement <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>.
This is effectively the same thing as adding a <ahref="https://doc.rust-lang.org/nightly/core/marker/struct.PhantomPinned.html"><code>PhantomPinned</code></a> to your
type.</p>
<p>Since this trait is <code>unsafe</code>, impls of it will be detected by the
<code>unsafe_code</code> lint, and by tools like <ahref="https://github.com/rust-secure-code/cargo-geiger"><code>cargo geiger</code></a>.</p>
<p>An <code>UnsafeUnpin</code> impl which, in addition to requiring that structurally
pinned fields be <ahref="https://doc.rust-lang.org/nightly/core/marker/trait.Unpin.html"title="Unpin"><code>Unpin</code></a>, imposes an additional requirement:</p>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.