1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

use {ComponentManager, EntityData};

pub struct Aspect<T: ComponentManager>(Box<Fn(&EntityData<T>, &T) -> bool + 'static>);

impl<T: ComponentManager> Aspect<T>
{
    pub fn all() -> Aspect<T>
    {
        Aspect(Box::new(|_, _| true))
    }

    pub fn none() -> Aspect<T>
    {
        Aspect(Box::new(|_, _| false))
    }

    #[doc(hidden)]
    pub fn __new(inner: Box<Fn(&EntityData<T>, &T) -> bool + 'static>) -> Aspect<T>
    {
        Aspect(inner)
    }

    pub fn check<'a>(&self, entity: &EntityData<'a, T>, components: &T) -> bool
    {
        (self.0)(entity, components)
    }
}