bevy_reflect

Trait GetField

Source
pub trait GetField {
    // Required methods
    fn get_field<T: Reflect>(&self, name: &str) -> Option<&T>;
    fn get_field_mut<T: Reflect>(&mut self, name: &str) -> Option<&mut T>;
}
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§

Source

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

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

Source

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

Returns a mutable reference to the value of the field named name, 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§

Source§

impl GetField for dyn Struct

Source§

impl<S: Struct> GetField for S