use core::any::TypeId;
use crate::{
archetype::Archetype, component::ComponentInfo, entity::EntityId, epoch::EpochId, Access,
};
pub use self::{
alt::{Alt, FetchAlt},
boolean::{
And, And2, And3, And4, And5, And6, And7, And8, BooleanFetch, BooleanFetchOp, BooleanQuery,
Or, Or2, Or3, Or4, Or5, Or6, Or7, Or8, Xor, Xor2, Xor3, Xor4, Xor5, Xor6, Xor7, Xor8,
},
borrow::{
FetchBorrowAllRead, FetchBorrowAnyRead, FetchBorrowAnyWrite, FetchBorrowOneRead,
FetchBorrowOneWrite, QueryBorrowAll, QueryBorrowAny, QueryBorrowOne,
},
copied::{Cpy, FetchCopied},
entities::{Entities, EntitiesFetch},
fetch::{Fetch, UnitFetch, VerifyFetch},
filter::{FilteredFetch, Not, With, Without},
modified::{
Modified, ModifiedFetchAlt, ModifiedFetchCopied, ModifiedFetchRead, ModifiedFetchWith,
ModifiedFetchWrite,
},
read::{FetchRead, Read},
with_epoch::{EpochOf, FetchEpoch},
write::{FetchWrite, Write},
};
mod alt;
mod boolean;
mod borrow;
mod copied;
mod entities;
mod fetch;
mod filter;
mod modified;
mod option;
mod read;
mod tuple;
mod with_epoch;
mod write;
pub trait AsQuery {
type Query: Query;
}
pub trait IntoQuery: AsQuery {
fn into_query(self) -> Self::Query;
}
pub unsafe trait IntoSendQuery: IntoQuery + AsSendQuery {}
unsafe impl<Q> IntoSendQuery for Q where Q: IntoQuery + AsSendQuery {}
pub trait DefaultQuery: AsQuery {
fn default_query() -> Self::Query;
}
pub unsafe trait DefaultSendQuery: DefaultQuery + AsSendQuery {}
unsafe impl<Q> DefaultSendQuery for Q where Q: DefaultQuery + AsSendQuery {}
pub struct WriteAlias;
pub unsafe trait Query: IntoQuery<Query = Self> + Copy + Send + Sync + 'static {
type Item<'a>: 'a;
type Fetch<'a>: Fetch<'a, Item = Self::Item<'a>> + 'a;
const MUTABLE: bool;
const FILTERS_ENTITIES: bool = false;
#[must_use]
fn component_access(&self, comp: &ComponentInfo) -> Result<Option<Access>, WriteAlias>;
#[must_use]
fn visit_archetype(&self, archetype: &Archetype) -> bool;
unsafe fn access_archetype(&self, archetype: &Archetype, f: impl FnMut(TypeId, Access));
#[must_use]
#[inline(always)]
fn visit_archetype_late(&self, archetype: &Archetype) -> bool {
debug_assert!(self.visit_archetype(archetype));
let _ = archetype;
true
}
#[must_use]
unsafe fn fetch<'a>(
&self,
arch_idx: u32,
archetype: &'a Archetype,
epoch: EpochId,
) -> Self::Fetch<'a>;
#[must_use]
#[inline(always)]
fn reserved_entity_item<'a>(&self, id: EntityId, idx: u32) -> Option<Self::Item<'a>> {
let _ = id;
let _ = idx;
None
}
}
pub unsafe trait ImmutableQuery: Query {
const CHECK_VALID: () = {
if Self::MUTABLE {
panic!("Immutable query cannot fetch mutable components");
}
};
}
pub unsafe trait SendQuery: Query {}
pub unsafe trait SendImmutableQuery: SendQuery + ImmutableQuery {}
unsafe impl<Q> SendImmutableQuery for Q where Q: SendQuery + ImmutableQuery {}
pub unsafe trait AsSendQuery: AsQuery {}
unsafe impl<Q> AsSendQuery for Q
where
Q: AsQuery,
Q::Query: SendQuery,
{
}
pub type QueryItem<'a, Q> = <<Q as AsQuery>::Query as Query>::Item<'a>;