rule_fns

Macro rule_fns 

Source
macro_rules! rule_fns {
    [$($x:expr),+ $(,)?] => { ... };
}
Expand description

A convenience macro to cast a list of fn pointers or closures to a uniform type.

Casting an fn pointer or closure to this type allows it to be passed to the engine alongside other such types. This is necessary since no two fn pointers or closures have the same type, and thus cannot be stored in a single collection without casting.

ยงExample

use tree_morph::prelude::*;
use uniplate::Uniplate;


#[derive(Debug, Clone, PartialEq, Eq, Uniplate)]
#[uniplate()]
struct Foo;

fn rule_a(_: &mut Commands<Foo, ()>, _: &Foo, _: &()) -> Option<Foo> {
    None
}

fn rule_b(_: &mut Commands<Foo, ()>, _: &Foo, _: &()) -> Option<Foo> {
    None
}

let rules = vec![
    rule_fns![rule_a],
    vec![rule_a as RuleFn<_, _>], // Same as above
    rule_fns![rule_b, |_, _, _| None], // Closures and fn pointers can be mixed
];