Trait bevy::reflect::Tuple

pub trait Tuple: 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) -> TupleFieldIter<'_> ;
    fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>>;
    fn clone_dynamic(&self) -> DynamicTuple;
}
Expand description

A trait used to power tuple-like operations via reflection.

This trait uses the Reflect trait to allow implementors to have their fields be dynamically addressed by index.

This trait is automatically implemented for arbitrary tuples of up to 12 elements, provided that each element implements Reflect.

§Example

use bevy_reflect::{Reflect, Tuple};

let foo = (123_u32, true);
assert_eq!(foo.field_len(), 2);

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.

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

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

fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>>

Drain the fields of this tuple to get a vector of owned values.

fn clone_dynamic(&self) -> DynamicTuple

Clones the struct into a DynamicTuple.

Trait Implementations§

§

impl GetTupleField for dyn Tuple

§

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.

Implementations on Foreign Types§

§

impl Tuple for ()

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<()>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A> Tuple for (A,)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A,)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B> Tuple for (A, B)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C> Tuple for (A, B, C)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D> Tuple for (A, B, C, D)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E> Tuple for (A, B, C, D, E)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F> Tuple for (A, B, C, D, E, F)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E, F)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F, G> Tuple for (A, B, C, D, E, F, G)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E, F, G)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F, G, H> Tuple for (A, B, C, D, E, F, G, H)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E, F, G, H)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F, G, H, I> Tuple for (A, B, C, D, E, F, G, H, I)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E, F, G, H, I)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F, G, H, I, J> Tuple for (A, B, C, D, E, F, G, H, I, J)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E, F, G, H, I, J)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F, G, H, I, J, K> Tuple for (A, B, C, D, E, F, G, H, I, J, K)

§

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) -> TupleFieldIter<'_>

§

fn drain(self: Box<(A, B, C, D, E, F, G, H, I, J, K)>) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

§

impl<A, B, C, D, E, F, G, H, I, J, K, L> Tuple for (A, B, C, D, E, F, G, H, I, J, K, L)

§

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) -> TupleFieldIter<'_>

§

fn drain( self: Box<(A, B, C, D, E, F, G, H, I, J, K, L)>, ) -> Vec<Box<dyn Reflect>>

§

fn clone_dynamic(&self) -> DynamicTuple

Implementors§