kaige_ecs/internals/query/filter/
any.rs

1use super::{
2    not::Not, passthrough::Passthrough, ActiveFilter, DynamicFilter, FilterResult, GroupMatcher,
3    LayoutFilter,
4};
5use crate::internals::{query::view::Fetch, storage::component::ComponentTypeId, world::WorldId};
6
7/// A filter which always matches `true`.
8#[derive(Debug, Clone, Default)]
9pub struct Any;
10
11impl GroupMatcher for Any {
12    fn can_match_group() -> bool {
13        false
14    }
15    fn group_components() -> Vec<ComponentTypeId> {
16        vec![]
17    }
18}
19
20impl LayoutFilter for Any {
21    fn matches_layout(&self, _: &[ComponentTypeId]) -> FilterResult {
22        FilterResult::Match(true)
23    }
24}
25
26impl DynamicFilter for Any {
27    fn prepare(&mut self, _: WorldId) {}
28
29    fn matches_archetype<F: Fetch>(&mut self, _: &F) -> FilterResult {
30        FilterResult::Match(true)
31    }
32}
33
34impl std::ops::Not for Any {
35    type Output = Not<Self>;
36
37    #[inline]
38    fn not(self) -> Self::Output {
39        Not { filter: self }
40    }
41}
42
43impl<Rhs: ActiveFilter> std::ops::BitAnd<Rhs> for Any {
44    type Output = Rhs;
45
46    #[inline]
47    fn bitand(self, rhs: Rhs) -> Self::Output {
48        rhs
49    }
50}
51
52impl std::ops::BitAnd<Passthrough> for Any {
53    type Output = Self;
54
55    #[inline]
56    fn bitand(self, _: Passthrough) -> Self::Output {
57        self
58    }
59}
60
61impl<Rhs: ActiveFilter> std::ops::BitOr<Rhs> for Any {
62    type Output = Self;
63
64    #[inline]
65    fn bitor(self, _: Rhs) -> Self::Output {
66        self
67    }
68}
69
70impl std::ops::BitOr<Passthrough> for Any {
71    type Output = Self;
72
73    #[inline]
74    fn bitor(self, _: Passthrough) -> Self::Output {
75        self
76    }
77}