bevy_reflect

Trait GetTupleStructField

Source
pub trait GetTupleStructField {
    // Required methods
    fn get_field<T: Reflect>(&self, index: usize) -> Option<&T>;
    fn get_field_mut<T: Reflect>(&mut self, index: usize) -> Option<&mut T>;
}
Expand description

A convenience trait which combines fetching and downcasting of tuple struct fields.

§Example

use bevy_reflect::{GetTupleStructField, Reflect};

#[derive(Reflect)]
struct Foo(String);

let mut foo = Foo("Hello, world!".to_string());

foo.get_field_mut::<String>(0).unwrap().truncate(5);
assert_eq!(foo.get_field::<String>(0), Some(&"Hello".to_string()));

Required Methods§

Source

fn get_field<T: Reflect>(&self, index: usize) -> Option<&T>

Returns a reference to the value of the field with index index, downcast to T.

Source

fn get_field_mut<T: Reflect>(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to the value of the field with index index, downcast to T.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§