1use std::marker::PhantomData;
2
3#[cfg(feature = "system")]
4use crate::system::SystemParm;
5use crate::{
6 iter::{EIter, Iter},
7 tools::{WorldFetch, WorldFilter},
8 world::World,
9};
10
11#[allow(unused_imports)]
12use crate::bundle::Components;
13#[derive(Clone)]
21pub struct Query<'a, F: WorldFetch, Q: WorldFilter = ()> {
22 world: &'a World,
23 _p: PhantomData<(F, Q)>,
24}
25
26impl<'a, F: WorldFetch, Q: WorldFilter> Query<'a, F, Q> {
27 pub fn new(world: &mut World) -> Query<'_, F, Q> {
28 Query {
29 world,
30 _p: PhantomData,
31 }
32 }
33
34 pub fn into_eiter(self) -> EIter<'a, F> {
35 unsafe {
36 #[allow(mutable_transmutes)]
37 EIter::new::<Q>(std::mem::transmute(self.world))
38 }
39 }
40}
41
42impl<'a, F: WorldFetch + 'a, Q: WorldFilter> IntoIterator for Query<'a, F, Q> {
43 type Item = F::Item<'a>;
44
45 type IntoIter = Iter<'a, F>;
46
47 fn into_iter(self) -> Self::IntoIter {
48 unsafe {
49 #[allow(mutable_transmutes)]
50 Iter::new::<Q>(std::mem::transmute(self.world))
51 }
52 }
53}
54
55#[cfg(feature = "system")]
56impl<F: WorldFetch, Q: WorldFilter> SystemParm for Query<'_, F, Q> {
57 unsafe fn build(world: &World) -> Self {
58 #[allow(mutable_transmutes)]
59 let world: &mut World = std::mem::transmute(world);
60 Query::<'_, F, Q>::new(world)
61 }
62
63 fn init(state: &mut crate::system::state::SystemState) {
64 F::alias_conflict(&mut state.alias_map);
65 }
66}