pub trait Tuple: Reflect {
fn field(&self, index: usize) -> Option<&(dyn Reflect + 'static)>;
fn field_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>;
fn field_len(&self) -> usize;
fn iter_fields(&self) -> TupleFieldIter<'_> ⓘ;
fn drain(
self: Box<Self, Global>
) -> Vec<Box<dyn Reflect + 'static, Global>, Global> ⓘ;
fn clone_dynamic(&self) -> DynamicTuple;
}
Expand description
A reflected Rust tuple.
This trait is automatically implemented for arbitrary tuples of up to 12
elements, provided that each element implements Reflect
.
Example
use bevy_reflect::Tuple;
let foo = ("blue".to_string(), 42_i32);
assert_eq!(foo.field_len(), 2);
let first = foo.field(0).unwrap();
assert_eq!(first.downcast_ref::<String>(), Some(&"blue".to_string()));
Required Methods§
fn field(&self, index: usize) -> Option<&(dyn Reflect + 'static)>
fn field(&self, index: usize) -> Option<&(dyn Reflect + '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 Reflect + 'static)>
fn field_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + '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, Global>
) -> Vec<Box<dyn Reflect + 'static, Global>, Global> ⓘ
fn drain(
self: Box<Self, Global>
) -> Vec<Box<dyn Reflect + 'static, Global>, Global> ⓘ
Drain the fields of this tuple to get a vector of owned values.
fn clone_dynamic(&self) -> DynamicTuple
fn clone_dynamic(&self) -> DynamicTuple
Clones the struct into a DynamicTuple
.