41 lines
20 KiB
HTML
41 lines
20 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="A trait used to power array-like operations via reflection."><title>Array 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="#">Array</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.drain" title="drain">drain</a></li><li><a href="#tymethod.get" title="get">get</a></li><li><a href="#tymethod.get_mut" title="get_mut">get_mut</a></li><li><a href="#tymethod.iter" title="iter">iter</a></li><li><a href="#tymethod.len" title="len">len</a></li></ul><h3><a href="#provided-methods">Provided Methods</a></h3><ul class="block"><li><a href="#method.clone_dynamic" title="clone_dynamic">clone_dynamic</a></li><li><a href="#method.get_represented_array_info" title="get_represented_array_info">get_represented_array_info</a></li><li><a href="#method.is_empty" title="is_empty">is_empty</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Array-for-%5BT;+N%5D" title="[T; N]">[T; N]</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">Array</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/array.rs.html#49-82">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Array: <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a> {
|
||
// Required methods
|
||
fn <a href="#tymethod.get" class="fn">get</a>(&self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.get_mut" class="fn">get_mut</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.len" class="fn">len</a>(&self) -> <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" class="fn">iter</a>(&self) -> <a class="struct" href="struct.ArrayIter.html" title="struct bevy_reflect::ArrayIter">ArrayIter</a><'_> <a href="#" class="tooltip" data-notable-ty="ArrayIter<'_>">ⓘ</a>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.drain" class="fn">drain</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><Self>) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>>>;
|
||
|
||
// Provided methods
|
||
fn <a href="#method.is_empty" class="fn">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.clone_dynamic" class="fn">clone_dynamic</a>(&self) -> <a class="struct" href="struct.DynamicArray.html" title="struct bevy_reflect::DynamicArray">DynamicArray</a> { ... }
|
||
<span class="item-spacer"></span> fn <a href="#method.get_represented_array_info" class="fn">get_represented_array_info</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&'static <a class="struct" href="struct.ArrayInfo.html" title="struct bevy_reflect::ArrayInfo">ArrayInfo</a>> { ... }
|
||
}</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/ch03-02-data-types.html#the-array-type">array-like</a> operations via <a href="index.html" title="mod bevy_reflect">reflection</a>.</p>
|
||
<p>This corresponds to true Rust arrays like <code>[T; N]</code>,
|
||
but also to any fixed-size linear sequence types.
|
||
It is expected that implementors of this trait uphold this contract
|
||
and maintain a fixed size as returned by the <a href="trait.Array.html#tymethod.len" title="method bevy_reflect::Array::len"><code>Array::len</code></a> method.</p>
|
||
<p>Due to the <a href="https://doc.rust-lang.org/book/ch17-02-trait-objects.html">type-erasing</a> nature of the reflection API as a whole,
|
||
this trait does not make any guarantees that the implementor’s elements
|
||
are homogeneous (i.e. all the same type).</p>
|
||
<p>This trait has a blanket implementation over Rust arrays of up to 32 items.
|
||
This implementation can technically contain more than 32,
|
||
but the blanket <a href="trait.GetTypeRegistration.html" title="trait bevy_reflect::GetTypeRegistration"><code>GetTypeRegistration</code></a> is only implemented up to the 32
|
||
item limit due to a <a href="https://github.com/serde-rs/serde/issues/1937">limitation</a> on <a href="../serde/de/trait.Deserialize.html" title="trait serde::de::Deserialize"><code>Deserialize</code></a>.</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, Array};
|
||
|
||
<span class="kw">let </span>foo: <span class="kw-2">&</span><span class="kw">dyn </span>Array = <span class="kw-2">&</span>[<span class="number">123_u32</span>, <span class="number">456_u32</span>, <span class="number">789_u32</span>];
|
||
<span class="macro">assert_eq!</span>(foo.len(), <span class="number">3</span>);
|
||
|
||
<span class="kw">let </span>field: <span class="kw-2">&</span><span class="kw">dyn </span>PartialReflect = foo.get(<span class="number">0</span>).unwrap();
|
||
<span class="macro">assert_eq!</span>(field.try_downcast_ref::<u32>(), <span class="prelude-val">Some</span>(<span class="kw-2">&</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.get" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#51">Source</a><h4 class="code-header">fn <a href="#tymethod.get" class="fn">get</a>(&self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>></h4></section></summary><div class="docblock"><p>Returns a reference to the element at <code>index</code>, or <code>None</code> if out of bounds.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.get_mut" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#54">Source</a><h4 class="code-header">fn <a href="#tymethod.get_mut" class="fn">get_mut</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>></h4></section></summary><div class="docblock"><p>Returns a mutable reference to the element at <code>index</code>, or <code>None</code> if out of bounds.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.len" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#57">Source</a><h4 class="code-header">fn <a href="#tymethod.len" class="fn">len</a>(&self) -> <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 elements in the array.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.iter" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#65">Source</a><h4 class="code-header">fn <a href="#tymethod.iter" class="fn">iter</a>(&self) -> <a class="struct" href="struct.ArrayIter.html" title="struct bevy_reflect::ArrayIter">ArrayIter</a><'_> <a href="#" class="tooltip" data-notable-ty="ArrayIter<'_>">ⓘ</a></h4></section></summary><div class="docblock"><p>Returns an iterator over the array.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.drain" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#68">Source</a><h4 class="code-header">fn <a href="#tymethod.drain" class="fn">drain</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><Self>) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>>></h4></section></summary><div class="docblock"><p>Drain the elements of this array to get a vector of owned values.</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.is_empty" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#60-62">Source</a><h4 class="code-header">fn <a href="#method.is_empty" class="fn">is_empty</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.bool.html">bool</a></h4></section></summary><div class="docblock"><p>Returns <code>true</code> if the collection contains no elements.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.clone_dynamic" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#71-76">Source</a><h4 class="code-header">fn <a href="#method.clone_dynamic" class="fn">clone_dynamic</a>(&self) -> <a class="struct" href="struct.DynamicArray.html" title="struct bevy_reflect::DynamicArray">DynamicArray</a></h4></section></summary><div class="docblock"><p>Clones the list, producing a <a href="struct.DynamicArray.html" title="struct bevy_reflect::DynamicArray"><code>DynamicArray</code></a>.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="method.get_represented_array_info" class="method"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#79-81">Source</a><h4 class="code-header">fn <a href="#method.get_represented_array_info" class="fn">get_represented_array_info</a>(&self) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&'static <a class="struct" href="struct.ArrayInfo.html" title="struct bevy_reflect::ArrayInfo">ArrayInfo</a>></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="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Array-for-%5BT;+N%5D" class="impl"><a class="src rightside" href="../src/bevy_reflect/impls/std.rs.html#1305-1332">Source</a><a href="#impl-Array-for-%5BT;+N%5D" class="anchor">§</a><h3 class="code-header">impl<T: <a class="trait" href="trait.Reflect.html" title="trait bevy_reflect::Reflect">Reflect</a> + MaybeTyped + <a class="trait" href="trait.TypePath.html" title="trait bevy_reflect::TypePath">TypePath</a> + <a class="trait" href="trait.GetTypeRegistration.html" title="trait bevy_reflect::GetTypeRegistration">GetTypeRegistration</a>, const N: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>> <a class="trait" href="trait.Array.html" title="trait bevy_reflect::Array">Array</a> for <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.array.html">[T; N]</a></h3></section></summary><div class="impl-items"><section id="method.get" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/impls/std.rs.html#1307-1309">Source</a><a href="#method.get" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.get" class="fn">get</a>(&self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>></h4></section><section id="method.get_mut" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/impls/std.rs.html#1312-1314">Source</a><a href="#method.get_mut" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.get_mut" class="fn">get_mut</a>(&mut self, index: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><&mut dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>></h4></section><section id="method.len" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/impls/std.rs.html#1317-1319">Source</a><a href="#method.len" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.len" class="fn">len</a>(&self) -> <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.usize.html">usize</a></h4></section><section id="method.iter" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/impls/std.rs.html#1322-1324">Source</a><a href="#method.iter" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.iter" class="fn">iter</a>(&self) -> <a class="struct" href="struct.ArrayIter.html" title="struct bevy_reflect::ArrayIter">ArrayIter</a><'_> <a href="#" class="tooltip" data-notable-ty="ArrayIter<'_>">ⓘ</a></h4></section><section id="method.drain" class="method trait-impl"><a class="src rightside" href="../src/bevy_reflect/impls/std.rs.html#1327-1331">Source</a><a href="#method.drain" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.drain" class="fn">drain</a>(self: <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><Self>) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a><<a class="struct" href="https://doc.rust-lang.org/1.84.0/alloc/boxed/struct.Box.html" title="struct alloc::boxed::Box">Box</a><dyn <a class="trait" href="trait.PartialReflect.html" title="trait bevy_reflect::PartialReflect">PartialReflect</a>>></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"><section id="impl-Array-for-DynamicArray" class="impl"><a class="src rightside" href="../src/bevy_reflect/array.rs.html#289-326">Source</a><a href="#impl-Array-for-DynamicArray" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Array.html" title="trait bevy_reflect::Array">Array</a> for <a class="struct" href="struct.DynamicArray.html" title="struct bevy_reflect::DynamicArray">DynamicArray</a></h3></section></div><script src="../trait.impl/bevy_reflect/array/trait.Array.js" data-ignore-extern-crates="std" async></script><script type="text/json" id="notable-traits-data">{"ArrayIter<'_>":"<h3>Notable traits for <code><a class=\"struct\" href=\"struct.ArrayIter.html\" title=\"struct bevy_reflect::ArrayIter\">ArrayIter</a><'a></code></h3><pre><code><div class=\"where\">impl<'a> <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.ArrayIter.html\" title=\"struct bevy_reflect::ArrayIter\">ArrayIter</a><'a></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> = &'a dyn <a class=\"trait\" href=\"trait.PartialReflect.html\" title=\"trait bevy_reflect::PartialReflect\">PartialReflect</a>;</div>"}</script></section></div></main></body></html> |