Trait bevy::reflect::TupleStruct

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§

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)>

Returns a mutable reference to the value of the field with index index as a &mut dyn Reflect.

fn field_len(&self) -> usize

Returns the number of fields in the tuple struct.

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

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

fn clone_dynamic(&self) -> DynamicTupleStruct

Clones the struct into a DynamicTupleStruct.

Trait Implementations§

§

impl GetTupleStructField for dyn TupleStruct

§

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.
§

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§

§

impl TupleStruct for AnimationTargetId
where AnimationTargetId: Any + Send + Sync, Uuid: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for DefaultSpatialScale
where DefaultSpatialScale: Any + Send + Sync, SpatialScale: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for SpatialScale
where SpatialScale: Any + Send + Sync, Vec3: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for Volume
where Volume: Any + Send + Sync, f32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for DenoiseCAS
where DenoiseCAS: Any + Send + Sync, bool: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for Camera3dDepthTextureUsage
where Camera3dDepthTextureUsage: Any + Send + Sync, u32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for ComponentId
where ComponentId: Any + Send + Sync, usize: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for Children
where Children: Any + Send + Sync, SmallVec<[Entity; 8]>: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for Parent
where Parent: Any + Send + Sync, Entity: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for TouchpadMagnify
where TouchpadMagnify: Any + Send + Sync, f32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for TouchpadRotate
where TouchpadRotate: Any + Send + Sync, f32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for DefaultOpaqueRendererMethod

§

impl TupleStruct for ManualTextureViewHandle
where ManualTextureViewHandle: Any + Send + Sync, u32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for MipBias
where MipBias: Any + Send + Sync, f32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for ClearColor
where ClearColor: Any + Send + Sync, Color: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for InheritedVisibility
where InheritedVisibility: Any + Send + Sync, bool: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for ViewVisibility
where ViewVisibility: Any + Send + Sync, bool: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for RenderLayers
where RenderLayers: Any + Send + Sync, u32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for Mesh2dHandle
where Mesh2dHandle: Any + Send + Sync, Handle<Mesh>: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for GlobalTransform
where GlobalTransform: Any + Send + Sync, Affine3A: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for BackgroundColor
where BackgroundColor: Any + Send + Sync, Color: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for BorderColor
where BorderColor: Any + Send + Sync, Color: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for TargetCamera
where TargetCamera: Any + Send + Sync, Entity: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for UiScale
where UiScale: Any + Send + Sync, f32: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for NormalizedWindowRef
where NormalizedWindowRef: Any + Send + Sync, Entity: FromReflect + TypePath + RegisterForReflection,

§

impl TupleStruct for DynamicTupleStruct

§

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

§

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