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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::view::{View, ViewMut};
use core::ops::Not as NotOps;

/// Used to filter out components.
/// Get and iterators will skip entities that have this component.
/// ### Example
/// ```
/// use shipyard::{EntitiesViewMut, IntoIter, Shiperator, View, ViewMut, World};
///
/// let world = World::new();
///
/// world.run(
///     |mut entities: EntitiesViewMut, mut usizes: ViewMut<usize>, mut u32s: ViewMut<u32>| {
///         entities.add_entity((&mut usizes, &mut u32s), (0usize, 1u32));
///         entities.add_entity((&mut usizes,), (2usize,));
///     },
/// );
///
/// world.run(|usizes: View<usize>, u32s: View<u32>| {
///     let mut iter = (&usizes, !&u32s).iter();
///     assert_eq!(iter.next(), Some((&2, ())));
///     assert_eq!(iter.next(), None);
///     let mut iter = (&usizes, &u32s).iter();
///     assert_eq!(iter.next(), Some((&0, &1)));
///     assert_eq!(iter.next(), None);
/// });
/// ```
#[derive(Copy, Clone)]
pub struct Not<T>(pub(crate) T);

impl<T> NotOps for &View<'_, T> {
    type Output = Not<Self>;
    fn not(self) -> Self::Output {
        Not(self)
    }
}

impl<T> NotOps for &ViewMut<'_, T> {
    type Output = Not<Self>;
    fn not(self) -> Self::Output {
        Not(self)
    }
}

impl<T> NotOps for &mut ViewMut<'_, T> {
    type Output = Not<Self>;
    fn not(self) -> Self::Output {
        Not(self)
    }
}