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

40 lines
17 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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="A trait used to power tuple struct-like operations via reflection."><title>TupleStruct 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="#">Tuple<wbr>Struct</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#example" title="Example">Example</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.clone_dynamic" title="clone_dynamic">clone_dynamic</a></li><li><a href="#tymethod.field" title="field">field</a></li><li><a href="#tymethod.field_len" title="field_len">field_len</a></li><li><a href="#tymethod.field_mut" title="field_mut">field_mut</a></li><li><a href="#tymethod.iter_fields" title="iter_fields">iter_fields</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.get_represented_tuple_struct_info" title="get_represented_tuple_struct_info">get_represented_tuple_struct_info</a></li></ul><h3><a href="#trait-implementations">Trait Implementations</a></h3><ul class="block trait-implementation"><li><a href="#impl-GetTupleStructField-for-dyn+TupleStruct" title="GetTupleStructField">GetTupleStructField</a></li></ul><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">TupleStruct</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/tuple_struct.rs.html#43-65">Source</a> </span></div><pre class="rust item-decl"><code>pub trait TupleStruct: <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a> {
// Required methods
fn <a href="#tymethod.field" class="fn">field</a>(&amp;self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.field_mut" class="fn">field_mut</a>(&amp;mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>&gt;;
<span class="item-spacer"></span> fn <a href="#tymethod.field_len" class="fn">field_len</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.iter_fields" class="fn">iter_fields</a>(&amp;self) -&gt; <a class="struct" href="struct.TupleStructFieldIter.html" title="struct bevy_reflect::TupleStructFieldIter">TupleStructFieldIter</a>&lt;'_&gt; <a href="#" class="tooltip" data-notable-ty="TupleStructFieldIter&lt;&#39;_&gt;"></a>;
<span class="item-spacer"></span> fn <a href="#tymethod.clone_dynamic" class="fn">clone_dynamic</a>(&amp;self) -&gt; <a class="struct" href="struct.DynamicTupleStruct.html" title="struct bevy_reflect::DynamicTupleStruct">DynamicTupleStruct</a>;
// Provided method
fn <a href="#method.get_represented_tuple_struct_info" class="fn">get_represented_tuple_struct_info</a>(
&amp;self,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;'static <a class="struct" href="struct.TupleStructInfo.html" title="struct bevy_reflect::TupleStructInfo">TupleStructInfo</a>&gt; { ... }
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait used to power <a href="https://doc.rust-lang.org/book/ch05-01-defining-structs.html#using-tuple-structs-without-named-fields-to-create-different-types">tuple struct-like</a> operations via <a href="index.html" title="mod bevy_reflect">reflection</a>.</p>
<p>This trait uses the <a href="trait.Reflect.html" title="trait bevy_reflect::Reflect"><code>Reflect</code></a> trait to allow implementors to have their fields
be dynamically addressed by index.</p>
<p>When using <a href="derive.Reflect.html" title="derive bevy_reflect::Reflect"><code>#[derive(Reflect)]</code></a> on a tuple struct,
this trait will be automatically implemented.</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::{PartialReflect, Reflect, TupleStruct};
<span class="attr">#[derive(Reflect)]
</span><span class="kw">struct </span>Foo(u32);
<span class="kw">let </span>foo = Foo(<span class="number">123</span>);
<span class="macro">assert_eq!</span>(foo.field_len(), <span class="number">1</span>);
<span class="kw">let </span>field: <span class="kw-2">&amp;</span><span class="kw">dyn </span>PartialReflect = foo.field(<span class="number">0</span>).unwrap();
<span class="macro">assert_eq!</span>(field.try_downcast_ref::&lt;u32&gt;(), <span class="prelude-val">Some</span>(<span class="kw-2">&amp;</span><span class="number">123</span>));</code></pre></div>
</div></details><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.field" class="method"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#46">Source</a><h4 class="code-header">fn <a href="#tymethod.field" class="fn">field</a>(&amp;self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>&gt;</h4></section></summary><div class="docblock"><p>Returns a reference to the value of the field with index <code>index</code> as a
<code>&amp;dyn Reflect</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.field_mut" class="method"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#50">Source</a><h4 class="code-header">fn <a href="#tymethod.field_mut" class="fn">field_mut</a>(&amp;mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;mut dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>&gt;</h4></section></summary><div class="docblock"><p>Returns a mutable reference to the value of the field with index <code>index</code>
as a <code>&amp;mut dyn Reflect</code>.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.field_len" class="method"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#53">Source</a><h4 class="code-header">fn <a href="#tymethod.field_len" class="fn">field_len</a>(&amp;self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a></h4></section></summary><div class="docblock"><p>Returns the number of fields in the tuple struct.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.iter_fields" class="method"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#56">Source</a><h4 class="code-header">fn <a href="#tymethod.iter_fields" class="fn">iter_fields</a>(&amp;self) -&gt; <a class="struct" href="struct.TupleStructFieldIter.html" title="struct bevy_reflect::TupleStructFieldIter">TupleStructFieldIter</a>&lt;'_&gt; <a href="#" class="tooltip" data-notable-ty="TupleStructFieldIter&lt;&#39;_&gt;"></a></h4></section></summary><div class="docblock"><p>Returns an iterator over the values of the tuple structs fields.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.clone_dynamic" class="method"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#59">Source</a><h4 class="code-header">fn <a href="#tymethod.clone_dynamic" class="fn">clone_dynamic</a>(&amp;self) -&gt; <a class="struct" href="struct.DynamicTupleStruct.html" title="struct bevy_reflect::DynamicTupleStruct">DynamicTupleStruct</a></h4></section></summary><div class="docblock"><p>Clones the struct into a <a href="struct.DynamicTupleStruct.html" title="struct bevy_reflect::DynamicTupleStruct"><code>DynamicTupleStruct</code></a>.</p>
</div></details></div><h2 id="provided-methods" class="section-header">Provided Methods<a href="#provided-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="method.get_represented_tuple_struct_info" class="method"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#62-64">Source</a><h4 class="code-header">fn <a href="#method.get_represented_tuple_struct_info" class="fn">get_represented_tuple_struct_info</a>(&amp;self) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;&amp;'static <a class="struct" href="struct.TupleStructInfo.html" title="struct bevy_reflect::TupleStructInfo">TupleStructInfo</a>&gt;</h4></section></summary><div class="docblock"><p>Will return <code>None</code> if <a href="enum.TypeInfo.html" title="enum bevy_reflect::TypeInfo"><code>TypeInfo</code></a> is not available.</p>
</div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-GetTupleStructField-for-dyn+TupleStruct" class="impl"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#209-219">Source</a><a href="#impl-GetTupleStructField-for-dyn+TupleStruct" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.GetTupleStructField.html" title="trait bevy_reflect::GetTupleStructField">GetTupleStructField</a> for dyn <a class="trait" href="trait.TupleStruct.html" title="trait bevy_reflect::TupleStruct">TupleStruct</a></h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.get_field" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#210-213">Source</a><a href="#method.get_field" class="anchor">§</a><h4 class="code-header">fn <a href="trait.GetTupleStructField.html#tymethod.get_field" class="fn">get_field</a>&lt;T: <a class="trait" href="trait.Reflect.html" title="trait bevy_reflect::Reflect">Reflect</a>&gt;(&amp;self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;T</a>&gt;</h4></section></summary><div class='docblock'>Returns a reference to the value of the field with index <code>index</code>,
downcast to <code>T</code>.</div></details><details class="toggle method-toggle" open><summary><section id="method.get_field_mut" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#215-218">Source</a><a href="#method.get_field_mut" class="anchor">§</a><h4 class="code-header">fn <a href="trait.GetTupleStructField.html#tymethod.get_field_mut" class="fn">get_field_mut</a>&lt;T: <a class="trait" href="trait.Reflect.html" title="trait bevy_reflect::Reflect">Reflect</a>&gt;(&amp;mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;mut T</a>&gt;</h4></section></summary><div class='docblock'>Returns a mutable reference to the value of the field with index
<code>index</code>, downcast to <code>T</code>.</div></details></div></details></div><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-TupleStruct-for-DynamicTupleStruct" class="impl"><a class="src rightside" href="../src/bevy_reflect/tuple_struct.rs.html#259-293">Source</a><a href="#impl-TupleStruct-for-DynamicTupleStruct" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.TupleStruct.html" title="trait bevy_reflect::TupleStruct">TupleStruct</a> for <a class="struct" href="struct.DynamicTupleStruct.html" title="struct bevy_reflect::DynamicTupleStruct">DynamicTupleStruct</a></h3></section></div><script src="../trait.impl/bevy_reflect/tuple_struct/trait.TupleStruct.js" async></script><script type="text/json" id="notable-traits-data">{"TupleStructFieldIter<'_>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.TupleStructFieldIter.html\" title=\"struct bevy_reflect::TupleStructFieldIter\">TupleStructFieldIter</a>&lt;'a&gt;</code></h3><pre><code><div class=\"where\">impl&lt;'a&gt; <a class=\"trait\" href=\"https://doc.rust-lang.org/1.84.0/core/iter/traits/iterator/trait.Iterator.html\" title=\"trait core::iter::traits::iterator::Iterator\">Iterator</a> for <a class=\"struct\" href=\"struct.TupleStructFieldIter.html\" title=\"struct bevy_reflect::TupleStructFieldIter\">TupleStructFieldIter</a>&lt;'a&gt;</div><div class=\"where\"> type <a href=\"https://doc.rust-lang.org/1.84.0/core/iter/traits/iterator/trait.Iterator.html#associatedtype.Item\" class=\"associatedtype\">Item</a> = &amp;'a dyn <a class=\"trait\" href=\"trait.PartialReflect.html\" title=\"trait bevy_reflect::PartialReflect\">PartialReflect</a>;</div>"}</script></section></div></main></body></html>