diff options
Diffstat (limited to 'ecs/src/query/options.rs')
-rw-r--r-- | ecs/src/query/options.rs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/ecs/src/query/options.rs b/ecs/src/query/options.rs deleted file mode 100644 index bbbe0a8..0000000 --- a/ecs/src/query/options.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::collections::HashSet; -use std::marker::PhantomData; - -use crate::component::Component; -use crate::EntityComponent; - -/// Query options. -pub trait Options -{ - fn entity_filter<'component>( - components: impl IntoIterator<Item = &'component EntityComponent>, - ) -> bool; -} - -impl Options for () -{ - fn entity_filter<'component>( - _: impl IntoIterator<Item = &'component EntityComponent>, - ) -> bool - { - true - } -} - -pub struct With<ComponentT> -where - ComponentT: Component, -{ - _pd: PhantomData<ComponentT>, -} - -impl<ComponentT> Options for With<ComponentT> -where - ComponentT: Component, -{ - fn entity_filter<'component>( - components: impl IntoIterator<Item = &'component EntityComponent>, - ) -> bool - { - let ids_set = components - .into_iter() - .map(|component| component.id) - .collect::<HashSet<_>>(); - - ids_set.contains(&ComponentT::id()) - } -} - -pub struct Not<OptionsT> -where - OptionsT: Options, -{ - _pd: PhantomData<OptionsT>, -} - -impl<OptionsT> Options for Not<OptionsT> -where - OptionsT: Options, -{ - fn entity_filter<'component>( - components: impl IntoIterator<Item = &'component EntityComponent>, - ) -> bool - { - !OptionsT::entity_filter(components) - } -} |