1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#![doc(hidden)] use super::{DefaultFilter, Fetch, IntoIndexableIter, IntoView, ReadOnly, ReadOnlyFetch, View}; use crate::internals::{ entity::Entity, iter::indexed::IndexedIter, permissions::Permissions, query::{ filter::{any::Any, passthrough::Passthrough, EntityFilterTuple}, QueryResult, }, storage::{ archetype::{Archetype, ArchetypeIndex}, component::{Component, ComponentTypeId}, Components, }, subworld::ComponentAccess, }; unsafe impl ReadOnly for Entity {} impl DefaultFilter for Entity { type Filter = EntityFilterTuple<Any, Passthrough>; } impl IntoView for Entity { type View = Self; } impl<'data> View<'data> for Entity { type Element = <Self::Fetch as IntoIndexableIter>::Item; type Fetch = EntityFetch<'data>; type Iter = Iter<'data>; type Read = [ComponentTypeId; 0]; type Write = [ComponentTypeId; 0]; #[inline] fn validate() {} #[inline] fn validate_access(_: &ComponentAccess) -> bool { true } #[inline] fn reads_types() -> Self::Read { [] } #[inline] fn writes_types() -> Self::Write { [] } #[inline] fn reads<D: Component>() -> bool { false } #[inline] fn writes<D: Component>() -> bool { false } #[inline] fn requires_permissions() -> Permissions<ComponentTypeId> { Permissions::default() } unsafe fn fetch( _: &'data Components, archetypes: &'data [Archetype], query: QueryResult<'data>, ) -> Self::Iter { Iter { archetypes, indexes: query.index().iter(), } } } #[doc(hidden)] pub struct Iter<'a> { archetypes: &'a [Archetype], indexes: std::slice::Iter<'a, ArchetypeIndex>, } impl<'a> Iterator for Iter<'a> { type Item = Option<EntityFetch<'a>>; #[inline] fn next(&mut self) -> Option<Self::Item> { self.indexes.next().map(|i| { Some(EntityFetch { entities: self.archetypes[*i].entities(), }) }) } } #[doc(hidden)] pub struct EntityFetch<'a> { entities: &'a [Entity], } unsafe impl<'a> ReadOnlyFetch for EntityFetch<'a> { #[inline] fn get_components(&self) -> Self::Data { &self.entities } } impl<'a> IntoIndexableIter for EntityFetch<'a> { type Item = &'a Entity; type IntoIter = IndexedIter<&'a [Entity]>; fn into_indexable_iter(self) -> Self::IntoIter { IndexedIter::new(self.entities) } } impl<'a> IntoIterator for EntityFetch<'a> { type Item = <Self as IntoIndexableIter>::Item; type IntoIter = <Self as IntoIndexableIter>::IntoIter; fn into_iter(self) -> Self::IntoIter { self.into_indexable_iter() } } impl<'a> Fetch for EntityFetch<'a> { type Data = &'a [Entity]; #[inline] fn into_components(self) -> Self::Data { self.entities } #[inline] fn find<C: 'static>(&self) -> Option<&[C]> { None } #[inline] fn find_mut<C: 'static>(&mut self) -> Option<&mut [C]> { None } #[inline] fn version<C: Component>(&self) -> Option<u64> { None } #[inline] fn accepted(&mut self) {} }