Trait bevy::reflect::GetField

pub trait GetField {
    // Required methods
    fn get_field<T>(&self, name: &str) -> Option<&T>
       where T: Reflect;
    fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
       where T: Reflect;
}
Expand description

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

Example

use bevy_reflect::{GetField, Reflect};

#[derive(Reflect)]
struct Foo {
    bar: String,
}

let mut foo = Foo { bar: "Hello, world!".to_string() };

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

Required Methods§

fn get_field<T>(&self, name: &str) -> Option<&T>where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.

Implementors§

§

impl GetField for dyn Struct + 'static

§

impl<S> GetField for Swhere S: Struct,