Macro moonshine_kind::kind

source ·
macro_rules! kind {
    ($T:ident is $U:ty) => { ... };
}
Expand description

A macro to safely implement CastInto for a pair of related Kinds.

See CastInto for more information.

§Usage


struct Fruit;

impl Kind for Fruit {
   type Filter = With<Apple>;
}

#[derive(Component)]
struct Apple;

// We can guarantee all entities with an `Apple` component are of kind `Fruit`:
kind!(Apple is Fruit);

fn eat_apple(apple: Instance<Apple>) {
   println!("Crunch!");
   // SAFE: Because we said so.
   eat_fruit(apple.cast_into());
}

fn eat_fruit(fruit: Instance<Fruit>) {
   println!("Yum!");
}