Trait Tuple
pub trait Tuple: PartialReflect {
// Required methods
fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>;
fn field_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>;
fn field_len(&self) -> usize;
fn iter_fields(&self) -> TupleFieldIter<'_> ⓘ;
fn drain(self: Box<Self>) -> Vec<Box<dyn PartialReflect>>;
// Provided methods
fn to_dynamic_tuple(&self) -> DynamicTuple { ... }
fn get_represented_tuple_info(&self) -> Option<&'static TupleInfo> { ... }
}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::{PartialReflect, Tuple};
let foo = (123_u32, true);
assert_eq!(foo.field_len(), 2);
let field: &dyn PartialReflect = foo.field(0).unwrap();
assert_eq!(field.try_downcast_ref::<u32>(), Some(&123));Required Methods§
fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>
Returns a reference to the value of the field with index index as a
&dyn Reflect.
fn field_mut(
&mut self,
index: usize,
) -> Option<&mut (dyn PartialReflect + 'static)>
fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>
Returns a mutable reference to the value of the field with index index
as a &mut dyn Reflect.
fn iter_fields(&self) -> TupleFieldIter<'_> ⓘ
fn iter_fields(&self) -> TupleFieldIter<'_> ⓘ
Returns an iterator over the values of the tuple’s fields.
fn drain(self: Box<Self>) -> Vec<Box<dyn PartialReflect>>
fn drain(self: Box<Self>) -> Vec<Box<dyn PartialReflect>>
Drain the fields of this tuple to get a vector of owned values.
Provided Methods§
fn to_dynamic_tuple(&self) -> DynamicTuple
fn to_dynamic_tuple(&self) -> DynamicTuple
Creates a new DynamicTuple from this tuple.
fn get_represented_tuple_info(&self) -> Option<&'static TupleInfo>
fn get_represented_tuple_info(&self) -> Option<&'static TupleInfo>
Will return None if TypeInfo is not available.