Files
phy/bevy_reflect/trait.ReflectRemote.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

50 lines
13 KiB
HTML

<!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="Marks a type as a reflectable wrapper for a remote type."><title>ReflectRemote in bevy_reflect - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="bevy_reflect" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="icon" href="https://bevyengine.org/assets/icon.png"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button><a class="logo-container" href="../bevy_reflect/index.html"><img src="https://bevyengine.org/assets/icon.png" alt=""></a></nav><nav class="sidebar"><div class="sidebar-crate"><a class="logo-container" href="../bevy_reflect/index.html"><img src="https://bevyengine.org/assets/icon.png" alt="logo"></a><h2><a href="../bevy_reflect/index.html">bevy_<wbr>reflect</a><span class="version">0.15.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Reflect<wbr>Remote</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#safety" title="Safety">Safety</a></li><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#required-associated-types">Required Associated Types</a></h3><ul class="block"><li><a href="#associatedtype.Remote" title="Remote">Remote</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.as_remote" title="as_remote">as_remote</a></li><li><a href="#tymethod.as_remote_mut" title="as_remote_mut">as_remote_mut</a></li><li><a href="#tymethod.as_wrapper" title="as_wrapper">as_wrapper</a></li><li><a href="#tymethod.as_wrapper_mut" title="as_wrapper_mut">as_wrapper_mut</a></li><li><a href="#tymethod.into_remote" title="into_remote">into_remote</a></li><li><a href="#tymethod.into_wrapper" title="into_wrapper">into_wrapper</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate bevy_<wbr>reflect</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">bevy_reflect</a></span><h1>Trait <span class="trait">ReflectRemote</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/bevy_reflect/remote.rs.html#47-64">Source</a> </span></div><pre class="rust item-decl"><code>pub trait ReflectRemote: <a class="trait" href="trait.Reflect.html" title="trait bevy_reflect::Reflect">Reflect</a> {
type <a href="#associatedtype.Remote" class="associatedtype">Remote</a>;
// Required methods
fn <a href="#tymethod.as_remote" class="fn">as_remote</a>(&amp;self) -&gt; &amp;Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.as_remote_mut" class="fn">as_remote_mut</a>(&amp;mut self) -&gt; &amp;mut Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.into_remote" class="fn">into_remote</a>(self) -&gt; Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.as_wrapper" class="fn">as_wrapper</a>(remote: &amp;Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>) -&gt; &amp;Self;
<span class="item-spacer"></span> fn <a href="#tymethod.as_wrapper_mut" class="fn">as_wrapper_mut</a>(remote: &amp;mut Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>) -&gt; &amp;mut Self;
<span class="item-spacer"></span> fn <a href="#tymethod.into_wrapper" class="fn">into_wrapper</a>(remote: Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>) -&gt; Self;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Marks a type as a <a href="trait.Reflect.html" title="trait bevy_reflect::Reflect">reflectable</a> wrapper for a remote type.</p>
<p>This allows types from external libraries (remote types) to be included in reflection.</p>
<h2 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h2>
<p>It is highly recommended to avoid implementing this trait manually and instead use the
<a href="attr.reflect_remote.html" title="attr bevy_reflect::reflect_remote"><code>#[reflect_remote]</code></a> attribute macro.
This is because the trait tends to rely on <a href="https://doc.rust-lang.org/1.84.0/core/intrinsics/fn.transmute.html" title="fn core::intrinsics::transmute"><code>transmute</code></a>, which is <a href="https://doc.rust-lang.org/1.71.0/nomicon/transmutes.html">very unsafe</a>.</p>
<p>The macro will ensure that the following safety requirements are met:</p>
<ul>
<li><code>Self</code> is a single-field tuple struct (i.e. a newtype) containing the remote type.</li>
<li><code>Self</code> is <code>#[repr(transparent)]</code> over the remote type.</li>
</ul>
<p>Additionally, the macro will automatically generate <a href="trait.Reflect.html" title="trait bevy_reflect::Reflect"><code>Reflect</code></a> and <a href="trait.FromReflect.html" title="trait bevy_reflect::FromReflect"><code>FromReflect</code></a> implementations,
along with compile-time assertions to validate that the safety requirements have been met.</p>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>bevy_reflect_derive::{reflect_remote, Reflect};
<span class="kw">mod </span>some_lib {
<span class="kw">pub struct </span>TheirType {
<span class="kw">pub </span>value: u32
}
}
<span class="attr">#[reflect_remote(some_lib::TheirType)]
</span><span class="kw">struct </span>MyType {
<span class="kw">pub </span>value: u32
}
<span class="attr">#[derive(Reflect)]
</span><span class="kw">struct </span>MyStruct {
<span class="attr">#[reflect(remote = MyType)]
</span>data: some_lib::TheirType,
}</code></pre></div>
</div></details><h2 id="required-associated-types" class="section-header">Required Associated Types<a href="#required-associated-types" class="anchor">§</a></h2><div class="methods"><details class="toggle" open><summary><section id="associatedtype.Remote" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#49">Source</a><h4 class="code-header">type <a href="#associatedtype.Remote" class="associatedtype">Remote</a></h4></section></summary><div class="docblock"><p>The remote type this type represents via reflection.</p>
</div></details></div><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.as_remote" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#52">Source</a><h4 class="code-header">fn <a href="#tymethod.as_remote" class="fn">as_remote</a>(&amp;self) -&gt; &amp;Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a></h4></section></summary><div class="docblock"><p>Converts a reference of this wrapper to a reference of its remote type.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.as_remote_mut" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#54">Source</a><h4 class="code-header">fn <a href="#tymethod.as_remote_mut" class="fn">as_remote_mut</a>(&amp;mut self) -&gt; &amp;mut Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a></h4></section></summary><div class="docblock"><p>Converts a mutable reference of this wrapper to a mutable reference of its remote type.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.into_remote" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#56">Source</a><h4 class="code-header">fn <a href="#tymethod.into_remote" class="fn">into_remote</a>(self) -&gt; Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a></h4></section></summary><div class="docblock"><p>Converts this wrapper into its remote type.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.as_wrapper" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#59">Source</a><h4 class="code-header">fn <a href="#tymethod.as_wrapper" class="fn">as_wrapper</a>(remote: &amp;Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>) -&gt; &amp;Self</h4></section></summary><div class="docblock"><p>Converts a reference of the remote type to a reference of this wrapper.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.as_wrapper_mut" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#61">Source</a><h4 class="code-header">fn <a href="#tymethod.as_wrapper_mut" class="fn">as_wrapper_mut</a>(remote: &amp;mut Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>) -&gt; &amp;mut Self</h4></section></summary><div class="docblock"><p>Converts a mutable reference of the remote type to a mutable reference of this wrapper.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.into_wrapper" class="method"><a class="src rightside" href="../src/bevy_reflect/remote.rs.html#63">Source</a><h4 class="code-header">fn <a href="#tymethod.into_wrapper" class="fn">into_wrapper</a>(remote: Self::<a class="associatedtype" href="trait.ReflectRemote.html#associatedtype.Remote" title="type bevy_reflect::ReflectRemote::Remote">Remote</a>) -&gt; Self</h4></section></summary><div class="docblock"><p>Converts the remote type into this wrapper.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/bevy_reflect/remote/trait.ReflectRemote.js" async></script></section></div></main></body></html>