use std::any::type_name; use std::marker::PhantomData; use crate::component::{ Component, Handle as ComponentHandle, HandleFromEntityComponentRef, HandleMut as ComponentHandleMut, }; use crate::query::{ TermWithField, TermWithoutField, TermsBuilder, TermsBuilderInterface, }; use crate::uid::With as WithUid; pub struct With where WithUidT: WithUid, { _pd: PhantomData, } impl TermWithoutField for With where WithUidT: WithUid, { fn apply_to_terms_builder( terms_builder: &mut TermsBuilder, ) { terms_builder.with::(); } } pub struct Without where WithUidT: WithUid, { _pd: PhantomData, } impl TermWithoutField for Without where WithUidT: WithUid, { fn apply_to_terms_builder( terms_builder: &mut TermsBuilder, ) { terms_builder.without::(); } } impl TermWithField for Option<&ComponentT> { type Field<'a> = Option>; fn apply_to_terms_builder( _terms_builder: &mut TermsBuilder, ) { } fn get_field<'world>( entity_handle: &crate::entity::Handle<'world>, world: &'world crate::World, ) -> Self::Field<'world> { Some( ComponentHandle::<'world, ComponentT>::from_entity_component_ref( Some( entity_handle .get_matching_components(ComponentT::id()) .next()?, ), world, ) .unwrap_or_else(|err| { panic!( "Creating handle to component {} failed: {err}", type_name::() ); }), ) } } impl TermWithField for Option<&mut ComponentT> { type Field<'a> = Option>; fn apply_to_terms_builder( _terms_builder: &mut TermsBuilder, ) { } fn get_field<'world>( entity_handle: &crate::entity::Handle<'world>, world: &'world crate::World, ) -> Self::Field<'world> { Some( ComponentHandleMut::<'world, ComponentT>::from_entity_component_ref( Some( entity_handle .get_matching_components(ComponentT::id()) .next()?, ), world, ) .unwrap_or_else(|err| { panic!( "Creating handle to component {} failed: {err}", type_name::() ); }), ) } }