Skip to main content

TupleStruct

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<'_> ⓘ;

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

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.

Provided Methods§

Source

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.

Source

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl TupleStruct for AspectRatio

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for ComponentId

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for Dir2

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for Dir3

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for Dir4

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for Dir3A

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for FloatOrd

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for GlobalTransform

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for HashedStr

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for IsResource

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for ObservedBy

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl TupleStruct for RemovedComponentEntity

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<C> TupleStruct for Inherited<C>
where C: Component + Clone + PartialEq + TypePath + FromReflect + MaybeTyped + RegisterForReflection, Inherited<C>: Any + Send + Sync,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<C> TupleStruct for Propagate<C>
where C: Component + Clone + PartialEq + TypePath + FromReflect + MaybeTyped + RegisterForReflection, Propagate<C>: Any + Send + Sync,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<C> TupleStruct for PropagateOver<C>
where PropagateOver<C>: Any + Send + Sync, C: TypePath, PhantomData<fn() -> C>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<C> TupleStruct for PropagateStop<C>
where PropagateStop<C>: Any + Send + Sync, C: TypePath, PhantomData<fn() -> C>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<K, V> TupleStruct for EntityEquivalentHashMap<K, V>
where K: EntityEquivalent + Hash + TypePath, EntityEquivalentHashMap<K, V>: Any + Send + Sync, V: TypePath, HashMap<K, V, EntityHash>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<K, V> TupleStruct for EntityEquivalentIndexMap<K, V>
where K: EntityEquivalent + Hash + TypePath, EntityEquivalentIndexMap<K, V>: Any + Send + Sync, V: TypePath, IndexMap<K, V, EntityHash>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<K> TupleStruct for EntityEquivalentHashSet<K>
where K: EntityEquivalent + Hash + TypePath, EntityEquivalentHashSet<K>: Any + Send + Sync, HashSet<K, EntityHash>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<K> TupleStruct for EntityEquivalentIndexSet<K>
where K: EntityEquivalent + Hash + TypePath, EntityEquivalentIndexSet<K>: Any + Send + Sync, IndexSet<K, EntityHash>: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<T> TupleStruct for Interned<T>
where T: Internable + 'static + TypePath + ?Sized, Interned<T>: Any + Send + Sync, &'static T: FromReflect + TypePath + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Source§

impl<V, W> TupleStruct for Sum<V, W>
where Sum<V, W>: Any + Send + Sync, V: TypePath + FromReflect + MaybeTyped + RegisterForReflection, W: TypePath + FromReflect + MaybeTyped + RegisterForReflection,

Source§

fn field(&self, index: usize) -> Option<&(dyn PartialReflect + 'static)>

Source§

fn field_mut( &mut self, index: usize, ) -> Option<&mut (dyn PartialReflect + 'static)>

Source§

fn field_len(&self) -> usize

Source§

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

Source§

fn to_dynamic_tuple_struct( &self, ) -> Result<DynamicTupleStruct, ReflectCloneError>

Implementors§