pub trait TupleStruct: 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) -> TupleStructFieldIter<'_> ⓘ;
// Provided methods
fn to_dynamic_tuple_struct(
&self,
) -> Result<DynamicTupleStruct, ReflectCloneError> { ... }
fn get_represented_tuple_struct_info(
&self,
) -> Option<&'static TupleStructInfo> { ... }
}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::{PartialReflect, Reflect, tuple_struct::TupleStruct};
#[derive(Reflect)]
struct Foo(u32);
let foo = Foo(123);
assert_eq!(foo.field_len(), 1);
let field: &dyn PartialReflect = foo.field(0).unwrap();
assert_eq!(field.try_downcast_ref::<u32>(), Some(&123));Required Methods§
Sourcefn 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.
Sourcefn 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.
Sourcefn iter_fields(&self) -> TupleStructFieldIter<'_> ⓘ
fn iter_fields(&self) -> TupleStructFieldIter<'_> ⓘ
Returns an iterator over the values of the tuple struct’s fields.
Provided Methods§
Sourcefn to_dynamic_tuple_struct(
&self,
) -> Result<DynamicTupleStruct, ReflectCloneError>
fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>
Creates a new DynamicTupleStruct from this tuple struct.
Returns an error if any field cannot be converted via PartialReflect::to_dynamic.
Sourcefn get_represented_tuple_struct_info(&self) -> Option<&'static TupleStructInfo>
fn get_represented_tuple_struct_info(&self) -> Option<&'static TupleStructInfo>
Will return None if TypeInfo is not available.
Trait Implementations§
Source§impl Display for dyn TupleStruct
impl Display for dyn TupleStruct
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".