Trait bevy_reflect::Tuple
source · pub trait Tuple: Reflect {
// Required methods
fn field(&self, index: usize) -> Option<&dyn Reflect>;
fn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>;
fn field_len(&self) -> usize;
fn iter_fields(&self) -> TupleFieldIter<'_> ⓘ;
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>>;
fn clone_dynamic(&self) -> DynamicTuple;
}
Expand description
A trait used to power tuple-like operations via reflection.
This trait uses the Reflect
trait to allow implementors to have their fields
be dynamically addressed by index.
This trait is automatically implemented for arbitrary tuples of up to 12
elements, provided that each element implements Reflect
.
§Example
use bevy_reflect::{Reflect, Tuple};
let foo = (123_u32, true);
assert_eq!(foo.field_len(), 2);
let field: &dyn Reflect = foo.field(0).unwrap();
assert_eq!(field.downcast_ref::<u32>(), Some(&123));
Required Methods§
sourcefn field(&self, index: usize) -> Option<&dyn Reflect>
fn field(&self, index: usize) -> Option<&dyn Reflect>
Returns a reference to the value of the field with index index
as a
&dyn Reflect
.
sourcefn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
Returns a mutable reference to the value of the field with index index
as a &mut dyn Reflect
.
sourcefn iter_fields(&self) -> TupleFieldIter<'_> ⓘ
fn iter_fields(&self) -> TupleFieldIter<'_> ⓘ
Returns an iterator over the values of the tuple’s fields.
sourcefn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>>
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>>
Drain the fields of this tuple to get a vector of owned values.
sourcefn clone_dynamic(&self) -> DynamicTuple
fn clone_dynamic(&self) -> DynamicTuple
Clones the struct into a DynamicTuple
.