Trait bevy::reflect::TupleStruct
[−]pub trait TupleStruct: 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) -> TupleStructFieldIter<'_>ⓘNotable traits for TupleStructFieldIter<'a>impl<'a> Iterator for TupleStructFieldIter<'a> type Item = &'a (dyn Reflect + 'static);
;
fn clone_dynamic(&self) -> DynamicTupleStruct;
}
Expand description
A reflected Rust tuple struct.
Implementors of this trait allow their tuple fields to be addressed by index.
This trait is automatically implemented for tuple struct types when using
#[derive(Reflect)]
.
use bevy_reflect::{Reflect, TupleStruct};
#[derive(Reflect)]
struct Foo(String);
let foo = Foo("Hello, world!".to_string());
assert_eq!(foo.field_len(), 1);
let first = foo.field(0).unwrap();
assert_eq!(first.downcast_ref::<String>(), Some(&"Hello, world!".to_string()));
Required Methods
Returns a reference to the value of the field with index index
as a
&dyn Reflect
.
Returns a mutable reference to the value of the field with index index
as a &mut dyn Reflect
.
fn iter_fields(&self) -> TupleStructFieldIter<'_>ⓘNotable traits for TupleStructFieldIter<'a>impl<'a> Iterator for TupleStructFieldIter<'a> type Item = &'a (dyn Reflect + 'static);
fn iter_fields(&self) -> TupleStructFieldIter<'_>ⓘNotable traits for TupleStructFieldIter<'a>impl<'a> Iterator for TupleStructFieldIter<'a> type Item = &'a (dyn Reflect + 'static);
Returns an iterator over the values of the tuple struct’s fields.
fn clone_dynamic(&self) -> DynamicTupleStruct
fn clone_dynamic(&self) -> DynamicTupleStruct
Clones the struct into a DynamicTupleStruct
.