pub trait TupleStruct: Reflect {
    // Required methods
    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<'_> ;
    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§

source

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.

source

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.

source

fn field_len(&self) -> usize

Returns the number of fields in the tuple struct.

source

fn iter_fields(&self) -> TupleStructFieldIter<'_>

Returns an iterator over the values of the tuple struct’s fields.

source

fn clone_dynamic(&self) -> DynamicTupleStruct

Clones the struct into a DynamicTupleStruct.

Trait Implementations§

source§

impl GetTupleStructField for dyn TupleStruct

source§

fn get_field<T>(&self, index: usize) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field with index index, downcast to T.
source§

fn get_field_mut<T>(&mut self, index: usize) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field with index index, downcast to T.

Implementors§

source§

impl TupleStruct for DefaultSpatialScale

source§

impl TupleStruct for SpatialScale

source§

impl TupleStruct for Volume

source§

impl TupleStruct for DenoiseCAS

source§

impl TupleStruct for Camera3dDepthTextureUsage

source§

impl TupleStruct for ComponentId

source§

impl TupleStruct for Children

source§

impl TupleStruct for Parent

source§

impl TupleStruct for TouchpadMagnify

source§

impl TupleStruct for TouchpadRotate

source§

impl TupleStruct for DefaultOpaqueRendererMethod

source§

impl TupleStruct for ManualTextureViewHandle

source§

impl TupleStruct for ClearColor

source§

impl TupleStruct for InheritedVisibility

source§

impl TupleStruct for ViewVisibility

source§

impl TupleStruct for RenderLayers

source§

impl TupleStruct for Mesh2dHandle

source§

impl TupleStruct for GlobalTransform

source§

impl TupleStruct for BackgroundColor

source§

impl TupleStruct for BorderColor

source§

impl TupleStruct for TargetCamera

source§

impl TupleStruct for UiScale

source§

impl TupleStruct for NormalizedWindowRef

source§

impl TupleStruct for DynamicTupleStruct

source§

impl<S> TupleStruct for NextState<S>

source§

impl<S> TupleStruct for State<S>
where S: States + TypePath + FromReflect, State<S>: Any + Send + Sync,