23 lines
5.2 KiB
HTML
23 lines
5.2 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="Derives the `FromReflect` trait."><title>FromReflect 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 derive"><!--[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="#">From<wbr>Reflect</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#field-attributes" title="Field Attributes">Field Attributes</a><ul><li><a href="#reflectignore" title="`#[reflect(ignore)]`"><code>#[reflect(ignore)]</code></a></li><li><a href="#reflectdefault" title="`#[reflect(default)]`"><code>#[reflect(default)]</code></a></li></ul></li></ul></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>Derive Macro <span class="derive">FromReflect</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"></span></div><pre class="rust item-decl"><code>#[derive(FromReflect)]
|
||
{
|
||
<span class="comment">// Attributes available to this derive:</span>
|
||
#[reflect]
|
||
}
|
||
</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Derives the <code>FromReflect</code> trait.</p>
|
||
<h2 id="field-attributes"><a class="doc-anchor" href="#field-attributes">§</a>Field Attributes</h2><h3 id="reflectignore"><a class="doc-anchor" href="#reflectignore">§</a><code>#[reflect(ignore)]</code></h3>
|
||
<p>The <code>#[reflect(ignore)]</code> attribute is shared with the <a href="derive.Reflect.html" title="derive bevy_reflect::Reflect"><code>#[derive(Reflect)]</code></a> macro and has much of the same
|
||
functionality in that it denotes that a field will be ignored by the reflection API.</p>
|
||
<p>The only major difference is that using it with this derive requires that the field implements [<code>Default</code>].
|
||
Without this requirement, there would be no way for <code>FromReflect</code> to automatically construct missing fields
|
||
that have been ignored.</p>
|
||
<h3 id="reflectdefault"><a class="doc-anchor" href="#reflectdefault">§</a><code>#[reflect(default)]</code></h3>
|
||
<p>If a field cannot be read, this attribute specifies a default value to be used in its place.</p>
|
||
<p>By default, this attribute denotes that the field’s type implements [<code>Default</code>].
|
||
However, it can also take in a path string to a user-defined function that will return the default value.
|
||
This takes the form: <code>#[reflect(default = "path::to::my_function")]</code> where <code>my_function</code> is a parameterless
|
||
function that must return some default value for the type.</p>
|
||
<p>Specifying a custom default can be used to give different fields their own specialized defaults,
|
||
or to remove the <code>Default</code> requirement on fields marked with <code>#[reflect(ignore)]</code>.
|
||
Additionally, either form of this attribute can be used to fill in fields that are simply missing,
|
||
such as when converting a partially-constructed dynamic type to a concrete one.</p>
|
||
</div></details></section></div></main></body></html> |