@@ -4,7 +4,7 @@ use crate::{
44} ;
55
66/// The data storage type that is being accessed.
7- #[ derive( Clone , Copy , Debug ) ]
7+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
88pub enum EcsAccessType {
99 /// Accesses [`Component`](crate::prelude::Component) data
1010 Component ( EcsAccessLevel ) ,
@@ -14,7 +14,7 @@ pub enum EcsAccessType {
1414
1515/// The way the data will be accessed and whether we take access on all the components on
1616/// an entity or just one component.
17- #[ derive( Clone , Copy , Debug ) ]
17+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
1818pub enum EcsAccessLevel {
1919 /// Reads [`Component`](crate::prelude::Component) with [`ComponentId`]
2020 Read ( ComponentId ) ,
@@ -47,7 +47,7 @@ pub enum EcsAccessLevel {
4747}
4848
4949/// Access level needed by [`QueryData`] fetch to the resource.
50- #[ derive( Copy , Clone , Debug ) ]
50+ #[ derive( Copy , Clone , Debug , PartialEq ) ]
5151pub enum ResourceAccessLevel {
5252 /// Reads the resource with [`ComponentId`]
5353 Read ( ComponentId ) ,
@@ -207,37 +207,40 @@ impl EcsAccessType {
207207}
208208
209209/// Error returned from [`has_conflicts`].
210- #[ derive( Clone , Copy , Debug ) ]
211- pub enum AccessError {
210+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
211+ pub enum QueryAccessError {
212+ /// Component was not registered on world
212213 ComponentNotRegistered ,
214+ /// The [`EcsAccessType`]'s conflict with each other
213215 Conflict ( EcsAccessType , EcsAccessType ) ,
216+ /// Entity did not have the requested components
214217 EntityDoesNotMatch ,
215218}
216219
217- impl core:: error:: Error for AccessError { }
220+ impl core:: error:: Error for QueryAccessError { }
218221
219- impl core:: fmt:: Display for AccessError {
222+ impl core:: fmt:: Display for QueryAccessError {
220223 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
221224 match * self {
222- AccessError :: ComponentNotRegistered => {
225+ QueryAccessError :: ComponentNotRegistered => {
223226 write ! (
224227 f,
225228 "At least one component in Q was not registered in world.
226229 Consider calling `World::register_component`"
227230 )
228231 }
229- AccessError :: Conflict ( ecs_access, ecs_access1) => {
232+ QueryAccessError :: Conflict ( ecs_access, ecs_access1) => {
230233 write ! ( f, "Conflict between {ecs_access:?} and {ecs_access1:?}" )
231234 }
232- AccessError :: EntityDoesNotMatch => {
235+ QueryAccessError :: EntityDoesNotMatch => {
233236 write ! ( f, "Entity does not match Q" )
234237 }
235238 }
236239 }
237240}
238241
239242/// Check if `Q` has any internal conflicts.
240- pub fn has_conflicts < Q : QueryData > ( components : & Components ) -> Result < ( ) , AccessError > {
243+ pub fn has_conflicts < Q : QueryData > ( components : & Components ) -> Result < ( ) , QueryAccessError > {
241244 let mut index_outer = 0 ;
242245 for ( i, access) in Q :: iter_access ( components, & mut index_outer) . enumerate ( ) {
243246 let mut index_inner = 0 ;
@@ -251,7 +254,7 @@ pub fn has_conflicts<Q: QueryData>(components: &Components) -> Result<(), Access
251254 continue ;
252255 }
253256 let ( Some ( access) , Some ( access_other) ) = ( access, access_other) else {
254- return Err ( AccessError :: ComponentNotRegistered ) ;
257+ return Err ( QueryAccessError :: ComponentNotRegistered ) ;
255258 } ;
256259
257260 // if we're in an except sequence, check if the sequence has ended
@@ -264,7 +267,7 @@ pub fn has_conflicts<Q: QueryData>(components: &Components) -> Result<(), Access
264267
265268 if sequence_ended {
266269 if !except_compatible {
267- return Err ( AccessError :: Conflict ( access, access_other) ) ;
270+ return Err ( QueryAccessError :: Conflict ( access, access_other) ) ;
268271 }
269272 except_compatible = false ;
270273 except_index = None ;
@@ -279,7 +282,7 @@ pub fn has_conflicts<Q: QueryData>(components: &Components) -> Result<(), Access
279282 except_index = Some ( index) ;
280283 except_compatible = true ;
281284 } ,
282- AccessCompatible :: Conflicts => return Err ( AccessError :: Conflict ( access, access_other) ) ,
285+ AccessCompatible :: Conflicts => return Err ( QueryAccessError :: Conflict ( access, access_other) ) ,
283286 AccessCompatible :: ConflictsExceptSecond ( index) => {
284287 except_index = Some ( index) ;
285288 }
@@ -288,7 +291,7 @@ pub fn has_conflicts<Q: QueryData>(components: &Components) -> Result<(), Access
288291
289292 if except_index. is_some ( ) && !except_compatible {
290293 if let ( Some ( access) , Some ( access_other) ) = ( access, last_access) {
291- return Err ( AccessError :: Conflict ( access, access_other) ) ;
294+ return Err ( QueryAccessError :: Conflict ( access, access_other) ) ;
292295 }
293296 }
294297 }
@@ -324,15 +327,15 @@ mod tests {
324327 // Conflicts
325328 assert ! ( matches!(
326329 has_conflicts:: <( & C1 , & mut C1 ) >( c) ,
327- Err ( AccessError :: Conflict ( _, _) )
330+ Err ( QueryAccessError :: Conflict ( _, _) )
328331 ) ) ;
329332 assert ! ( matches!(
330333 has_conflicts:: <( & mut C1 , & C1 ) >( c) ,
331- Err ( AccessError :: Conflict ( _, _) )
334+ Err ( QueryAccessError :: Conflict ( _, _) )
332335 ) ) ;
333336 assert ! ( matches!(
334337 has_conflicts:: <( & mut C1 , & mut C1 ) >( c) ,
335- Err ( AccessError :: Conflict ( _, _) )
338+ Err ( QueryAccessError :: Conflict ( _, _) )
336339 ) ) ;
337340 }
338341
@@ -351,35 +354,35 @@ mod tests {
351354 // Conflicts
352355 assert ! ( matches!(
353356 has_conflicts:: <( EntityRef , & mut C1 ) >( c) ,
354- Err ( AccessError :: Conflict ( _, _) )
357+ Err ( QueryAccessError :: Conflict ( _, _) )
355358 ) ) ;
356359 assert ! ( matches!(
357360 has_conflicts:: <( & mut C1 , EntityRef ) >( c) ,
358- Err ( AccessError :: Conflict ( _, _) )
361+ Err ( QueryAccessError :: Conflict ( _, _) )
359362 ) ) ;
360363 assert ! ( matches!(
361364 has_conflicts:: <( EntityMut , & C1 ) >( c) ,
362- Err ( AccessError :: Conflict ( _, _) )
365+ Err ( QueryAccessError :: Conflict ( _, _) )
363366 ) ) ;
364367 assert ! ( matches!(
365368 has_conflicts:: <( & C1 , EntityMut ) >( c) ,
366- Err ( AccessError :: Conflict ( _, _) )
369+ Err ( QueryAccessError :: Conflict ( _, _) )
367370 ) ) ;
368371 assert ! ( matches!(
369372 has_conflicts:: <( EntityMut , & mut C1 ) >( c) ,
370- Err ( AccessError :: Conflict ( _, _) )
373+ Err ( QueryAccessError :: Conflict ( _, _) )
371374 ) ) ;
372375 assert ! ( matches!(
373376 has_conflicts:: <( & mut C1 , EntityMut ) >( c) ,
374- Err ( AccessError :: Conflict ( _, _) )
377+ Err ( QueryAccessError :: Conflict ( _, _) )
375378 ) ) ;
376379 assert ! ( matches!(
377380 has_conflicts:: <( EntityMut , EntityRef ) >( c) ,
378- Err ( AccessError :: Conflict ( _, _) )
381+ Err ( QueryAccessError :: Conflict ( _, _) )
379382 ) ) ;
380383 assert ! ( matches!(
381384 has_conflicts:: <( EntityRef , EntityMut ) >( c) ,
382- Err ( AccessError :: Conflict ( _, _) )
385+ Err ( QueryAccessError :: Conflict ( _, _) )
383386 ) ) ;
384387 }
385388
@@ -403,11 +406,11 @@ mod tests {
403406 // Conflicts
404407 assert ! ( matches!(
405408 has_conflicts:: <( EntityRefExcept <C1 >, & mut C2 ) >( c) ,
406- Err ( AccessError :: Conflict ( _, _) )
409+ Err ( QueryAccessError :: Conflict ( _, _) )
407410 ) ) ;
408411 assert ! ( matches!(
409412 has_conflicts:: <( & mut C2 , EntityRefExcept <C1 >) >( c) ,
410- Err ( AccessError :: Conflict ( _, _) )
413+ Err ( QueryAccessError :: Conflict ( _, _) )
411414 ) ) ;
412415 }
413416
@@ -430,19 +433,19 @@ mod tests {
430433 // Conflicts
431434 assert ! ( matches!(
432435 has_conflicts:: <( & C2 , EntityMutExcept <C1 >) >( c) ,
433- Err ( AccessError :: Conflict ( _, _) )
436+ Err ( QueryAccessError :: Conflict ( _, _) )
434437 ) ) ;
435438 assert ! ( matches!(
436439 has_conflicts:: <( EntityMutExcept <C1 >, & C2 ) >( c) ,
437- Err ( AccessError :: Conflict ( _, _) )
440+ Err ( QueryAccessError :: Conflict ( _, _) )
438441 ) ) ;
439442 assert ! ( matches!(
440443 has_conflicts:: <( EntityMutExcept <C1 >, & mut C2 ) >( c) ,
441- Err ( AccessError :: Conflict ( _, _) )
444+ Err ( QueryAccessError :: Conflict ( _, _) )
442445 ) ) ;
443446 assert ! ( matches!(
444447 has_conflicts:: <( & mut C2 , EntityMutExcept <C1 >) >( c) ,
445- Err ( AccessError :: Conflict ( _, _) )
448+ Err ( QueryAccessError :: Conflict ( _, _) )
446449 ) ) ;
447450 }
448451}
0 commit comments