use std::any::type_name; use std::marker::PhantomData; use crate::component::{Component, HandleFromEntityComponentRef, Ref as ComponentRef}; 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 where ComponentRefT: ComponentRef, { 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( ComponentRefT::Handle::<'world>::from_entity_component_ref( Some( entity_handle .get_matching_components(ComponentRefT::Component::id()) .next()?, ), world, ) .unwrap_or_else(|err| { panic!( "Creating handle to component {} failed: {err}", type_name::() ); }), ) } }