Trait bevy_reflect::TupleStruct
source · pub trait TupleStruct: 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) -> TupleStructFieldIter<'_> ⓘ;
fn clone_dynamic(&self) -> DynamicTupleStruct;
}
Expand description
A trait used to power tuple struct-like operations via reflection.
This trait uses the Reflect
trait to allow implementors to have their fields
be dynamically addressed by index.
When using #[derive(Reflect)]
on a tuple struct,
this trait will be automatically implemented.
§Example
use bevy_reflect::{Reflect, TupleStruct};
#[derive(Reflect)]
struct Foo(u32);
let foo = Foo(123);
assert_eq!(foo.field_len(), 1);
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) -> TupleStructFieldIter<'_> ⓘ
fn iter_fields(&self) -> TupleStructFieldIter<'_> ⓘ
Returns an iterator over the values of the tuple struct’s fields.
sourcefn clone_dynamic(&self) -> DynamicTupleStruct
fn clone_dynamic(&self) -> DynamicTupleStruct
Clones the struct into a DynamicTupleStruct
.