bevy_reflect

Trait Array

Source
pub trait Array: PartialReflect {
    // Required methods
    fn get(&self, index: usize) -> Option<&dyn PartialReflect>;
    fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>;
    fn len(&self) -> usize;
    fn iter(&self) -> ArrayIter<'_> ;
    fn drain(self: Box<Self>) -> Vec<Box<dyn PartialReflect>>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn clone_dynamic(&self) -> DynamicArray { ... }
    fn get_represented_array_info(&self) -> Option<&'static ArrayInfo> { ... }
}
Expand description

A trait used to power array-like operations via reflection.

This corresponds to true Rust arrays like [T; N], 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 Array::len method.

Due to the type-erasing 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).

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 GetTypeRegistration is only implemented up to the 32 item limit due to a limitation on Deserialize.

§Example

use bevy_reflect::{PartialReflect, Array};

let foo: &dyn Array = &[123_u32, 456_u32, 789_u32];
assert_eq!(foo.len(), 3);

let field: &dyn PartialReflect = foo.get(0).unwrap();
assert_eq!(field.try_downcast_ref::<u32>(), Some(&123));

Required Methods§

Source

fn get(&self, index: usize) -> Option<&dyn PartialReflect>

Returns a reference to the element at index, or None if out of bounds.

Source

fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>

Returns a mutable reference to the element at index, or None if out of bounds.

Source

fn len(&self) -> usize

Returns the number of elements in the array.

Source

fn iter(&self) -> ArrayIter<'_>

Returns an iterator over the array.

Source

fn drain(self: Box<Self>) -> Vec<Box<dyn PartialReflect>>

Drain the elements of this array to get a vector of owned values.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the collection contains no elements.

Source

fn clone_dynamic(&self) -> DynamicArray

Clones the list, producing a DynamicArray.

Source

fn get_represented_array_info(&self) -> Option<&'static ArrayInfo>

Will return None if TypeInfo is not available.

Implementations on Foreign Types§

Source§

impl<T: Reflect + MaybeTyped + TypePath + GetTypeRegistration, const N: usize> Array for [T; N]

Source§

fn get(&self, index: usize) -> Option<&dyn PartialReflect>

Source§

fn get_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>

Source§

fn len(&self) -> usize

Source§

fn iter(&self) -> ArrayIter<'_>

Source§

fn drain(self: Box<Self>) -> Vec<Box<dyn PartialReflect>>

Implementors§