bevy::prelude

Trait TupleStruct

source
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<'_> ;
    fn clone_dynamic(&self) -> DynamicTupleStruct;

    // Provided method
    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, 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§

source

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.

source

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.

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.

Provided Methods§

source

fn get_represented_tuple_struct_info(&self) -> Option<&'static TupleStructInfo>

Will return None if TypeInfo is not available.

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 ComponentId
where ComponentId: Any + Send + Sync, usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

source§

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

source§

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

source§

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

source§

impl TupleStruct for PanGesture
where PanGesture: Any + Send + Sync, Vec2: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

source§

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

source§

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

source§

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

source§

impl TupleStruct for Dir2
where Dir2: Any + Send + Sync, Vec2: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

source§

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

source§

impl TupleStruct for Dir3A
where Dir3A: Any + Send + Sync, Vec3A: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

source§

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

source§

impl TupleStruct for DynamicTupleStruct

source§

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