Macro gear_objects::find_trait
source · macro_rules! find_trait { ($component:expr, $trait:ty) => { ... }; }
Expand description
Returns an optional reference to a trait for an object within the component.
§Examples
#![feature(lazy_cell)]
use gear_objects::*;
use paste::paste;
struct Apple {}
register_type!(Apple);
trait Fruit {
fn eat(&self) -> String;
}
register_type!(Fruit);
impl Fruit for Apple {
fn eat(&self) -> String {
"yum!".to_owned()
}
}
let apple = Apple {};
let mut component = Component::new("apple");
add_object!(component, Apple, apple, [Fruit]);
let fruit = find_trait!(component, Fruit);
assert_eq!(fruit.unwrap().eat(), "yum!");