Trait bevy::reflect::Tuple

source ·
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§

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.

source

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

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

source

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

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

source

fn clone_dynamic(&self) -> DynamicTuple

Clones the struct into a DynamicTuple.

Trait Implementations§

source§

impl GetTupleField for dyn Tuple

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.

Implementations on Foreign Types§

source§

impl Tuple for ()

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

impl<A> Tuple for (A,)
where A: Reflect + TypePath,

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

impl<A, B> Tuple for (A, B)
where A: Reflect + TypePath, B: Reflect + TypePath,

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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)

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

source§

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)

source§

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

source§

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

source§

fn field_len(&self) -> usize

source§

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

source§

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

source§

fn clone_dynamic(&self) -> DynamicTuple

Implementors§