@@ -82,7 +82,7 @@ impl<T: HasSchema> ComponentStore<T> {
8282 self . untyped . get_mut_or_insert ( entity, f)
8383 }
8484
85- /// Get mutable references to the component data for multiple entities at the same time.
85+ /// Get mutable references s to the component data for multiple entities at the same time.
8686 ///
8787 /// # Panics
8888 ///
@@ -109,27 +109,6 @@ impl<T: HasSchema> ComponentStore<T> {
109109 self . untyped . remove ( entity)
110110 }
111111
112- /// Gets an immutable reference to the component if there is exactly one instance of it.
113- #[ inline]
114- pub fn get_single_with_bitset ( & self , bitset : Rc < BitSetVec > ) -> Result < & T , QuerySingleError > {
115- // SOUND: we know the schema matches.
116- self . untyped
117- . get_single_with_bitset ( bitset)
118- . map ( |x| unsafe { x. cast_into_unchecked ( ) } )
119- }
120-
121- /// Gets a mutable reference to the component if there is exactly one instance of it.
122- #[ inline]
123- pub fn get_single_with_bitset_mut (
124- & mut self ,
125- bitset : Rc < BitSetVec > ,
126- ) -> Result < & mut T , QuerySingleError > {
127- // SOUND: we know the schema matches.
128- self . untyped
129- . get_single_with_bitset_mut ( bitset)
130- . map ( |x| unsafe { x. cast_into_mut_unchecked ( ) } )
131- }
132-
133112 /// Iterates immutably over all components of this type.
134113 /// Very fast but doesn't allow joining with other component types.
135114 #[ inline]
@@ -157,15 +136,6 @@ impl<T: HasSchema> ComponentStore<T> {
157136///
158137/// Automatically implemented for [`ComponentStore`].
159138pub trait ComponentIterBitset < ' a , T : HasSchema > {
160- /// Gets an immutable reference to the component if there is exactly one instance of it.
161- fn get_single_with_bitset ( & self , bitset : Rc < BitSetVec > ) -> Result < & T , QuerySingleError > ;
162-
163- /// Gets a mutable reference to the component if there is exactly one instance of it.
164- fn get_single_mut_with_bitset (
165- & mut self ,
166- bitset : Rc < BitSetVec > ,
167- ) -> Result < & mut T , QuerySingleError > ;
168-
169139 /// Iterates immutably over the components of this type where `bitset`
170140 /// indicates the indices of entities.
171141 /// Slower than `iter()` but allows joining between multiple component types.
@@ -203,27 +173,6 @@ pub trait ComponentIterBitset<'a, T: HasSchema> {
203173}
204174
205175impl < ' a , T : HasSchema > ComponentIterBitset < ' a , T > for ComponentStore < T > {
206- /// Gets an immutable reference to the component if there is exactly one instance of it.
207- fn get_single_with_bitset ( & self , bitset : Rc < BitSetVec > ) -> Result < & T , QuerySingleError > {
208- // SOUND: we know the schema matches.
209- fn map < T > ( r : SchemaRef ) -> & T {
210- unsafe { r. cast_into_unchecked ( ) }
211- }
212- self . untyped . get_single_with_bitset ( bitset) . map ( map)
213- }
214-
215- /// Gets a mutable reference to the component if there is exactly one instance of it.
216- fn get_single_mut_with_bitset (
217- & mut self ,
218- bitset : Rc < BitSetVec > ,
219- ) -> Result < & mut T , QuerySingleError > {
220- // SOUND: we know the schema matches.
221- fn map < T > ( r : SchemaRefMut ) -> & mut T {
222- unsafe { r. cast_into_mut_unchecked ( ) }
223- }
224- self . untyped . get_single_with_bitset_mut ( bitset) . map ( map)
225- }
226-
227176 /// Iterates immutably over the components of this type where `bitset`
228177 /// indicates the indices of entities.
229178 /// Slower than `iter()` but allows joining between multiple component types.
@@ -257,7 +206,7 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
257206 #[ inline]
258207 fn iter_mut_with_bitset ( & mut self , bitset : Rc < BitSetVec > ) -> ComponentBitsetIteratorMut < T > {
259208 // SOUND: we know the schema matches.
260- fn map < T > ( r : SchemaRefMut ) -> & mut T {
209+ fn map < T > ( r : SchemaRefMut < ' _ > ) -> & mut T {
261210 unsafe { r. cast_into_mut_unchecked ( ) }
262211 }
263212
@@ -300,16 +249,14 @@ impl<'a, T: HasSchema> ComponentIterBitset<'a, T> for ComponentStore<T> {
300249
301250#[ cfg( test) ]
302251mod tests {
303- use std:: rc:: Rc ;
304-
305252 use crate :: prelude:: * ;
306253
307- #[ derive( Debug , Clone , PartialEq , Eq , HasSchema , Default ) ]
308- #[ repr( C ) ]
309- struct A ( String ) ;
310-
311254 #[ test]
312255 fn create_remove_components ( ) {
256+ #[ derive( Debug , Clone , PartialEq , Eq , HasSchema , Default ) ]
257+ #[ repr( C ) ]
258+ struct A ( String ) ;
259+
313260 let mut entities = Entities :: default ( ) ;
314261 let e1 = entities. create ( ) ;
315262 let e2 = entities. create ( ) ;
@@ -328,6 +275,10 @@ mod tests {
328275
329276 #[ test]
330277 fn get_mut_or_insert ( ) {
278+ #[ derive( Debug , Clone , PartialEq , Eq , HasSchema , Default ) ]
279+ #[ repr( C ) ]
280+ struct A ( String ) ;
281+
331282 let mut entities = Entities :: default ( ) ;
332283 let e1 = entities. create ( ) ;
333284
@@ -347,129 +298,4 @@ mod tests {
347298 // Test that existing component is retrieved
348299 assert_eq ! ( comp. 0 , "Test2" ) ;
349300 }
350-
351- #[ test]
352- fn single_returns_none_when_empty ( ) {
353- let storage = ComponentStore :: < A > :: default ( ) ;
354- let bitset = Rc :: new ( {
355- let mut entities = Entities :: default ( ) ;
356- entities. create ( ) ;
357- entities. bitset ( ) . clone ( )
358- } ) ;
359-
360- let maybe_comp = storage. get_single_with_bitset ( bitset) ;
361-
362- assert_eq ! ( maybe_comp, Err ( QuerySingleError :: NoEntities ) ) ;
363- }
364-
365- #[ test]
366- fn single_returns_some_single ( ) {
367- let mut storage = ComponentStore :: < A > :: default ( ) ;
368- let mut entities = Entities :: default ( ) ;
369-
370- // Create some dummies so that the target entity isn't 0
371- ( 0 ..3 ) . map ( |_| entities. create ( ) ) . count ( ) ;
372-
373- let e = entities. create ( ) ;
374- let a = A ( "a" . to_string ( ) ) ;
375- storage. insert ( e, a. clone ( ) ) ;
376-
377- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
378-
379- let maybe_comp = storage. get_single_with_bitset ( bitset) ;
380-
381- assert_eq ! ( maybe_comp, Ok ( & a) ) ;
382- }
383-
384- #[ test]
385- fn single_returns_none_when_more_than_1 ( ) {
386- let mut entities = Entities :: default ( ) ;
387- let mut storage = ComponentStore :: < A > :: default ( ) ;
388-
389- ( 0 ..3 )
390- . map ( |i| storage. insert ( entities. create ( ) , A ( i. to_string ( ) ) ) )
391- . count ( ) ;
392-
393- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
394-
395- let maybe_comp = storage. get_single_with_bitset ( bitset) ;
396-
397- assert_eq ! ( maybe_comp, Err ( QuerySingleError :: MultipleEntities ) ) ;
398- }
399-
400- #[ test]
401- fn iter_with_bitset ( ) {
402- let mut entities = Entities :: default ( ) ;
403- let mut storage = ComponentStore :: < A > :: default ( ) ;
404-
405- {
406- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
407-
408- let mut comp_iter = storage. iter_with_bitset ( bitset. clone ( ) ) ;
409- assert_eq ! ( comp_iter. next( ) , None ) ;
410-
411- let mut comp_mut_iter = storage. iter_mut_with_bitset ( bitset) ;
412- assert_eq ! ( comp_mut_iter. next( ) , None ) ;
413- }
414-
415- {
416- let e = entities. create ( ) ;
417- let mut a = A ( "e" . to_string ( ) ) ;
418- storage. insert ( e, a. clone ( ) ) ;
419-
420- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
421-
422- let mut comp_iter = storage. iter_with_bitset ( bitset. clone ( ) ) ;
423- assert_eq ! ( comp_iter. next( ) , Some ( & a) ) ;
424-
425- let mut comp_mut_iter = storage. iter_mut_with_bitset ( bitset) ;
426- assert_eq ! ( comp_mut_iter. next( ) , Some ( & mut a) ) ;
427-
428- entities. kill ( e) ;
429- }
430- }
431-
432- #[ test]
433- fn iter_with_bitset_optional ( ) {
434- let mut entities = Entities :: default ( ) ;
435- let mut storage = ComponentStore :: < A > :: default ( ) ;
436-
437- {
438- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
439-
440- let mut comp_iter = storage. iter_with_bitset_optional ( bitset. clone ( ) ) ;
441- assert_eq ! ( comp_iter. next( ) , None ) ;
442-
443- let mut comp_mut_iter = storage. iter_mut_with_bitset_optional ( bitset) ;
444- assert_eq ! ( comp_mut_iter. next( ) , None ) ;
445- }
446-
447- {
448- let e = entities. create ( ) ;
449- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
450-
451- let mut comp_iter = storage. iter_with_bitset_optional ( bitset. clone ( ) ) ;
452- assert_eq ! ( comp_iter. next( ) , Some ( None ) ) ;
453-
454- let mut comp_mut_iter = storage. iter_mut_with_bitset_optional ( bitset) ;
455- assert_eq ! ( comp_mut_iter. next( ) , Some ( None ) ) ;
456-
457- entities. kill ( e) ;
458- }
459-
460- {
461- let e = entities. create ( ) ;
462- let mut a = A ( "e" . to_string ( ) ) ;
463- storage. insert ( e, a. clone ( ) ) ;
464- let bitset = Rc :: new ( entities. bitset ( ) . clone ( ) ) ;
465-
466- let mut comp_iter = storage. iter_with_bitset_optional ( bitset. clone ( ) ) ;
467- assert_eq ! ( comp_iter. next( ) , Some ( Some ( & a) ) ) ;
468-
469- let mut comp_mut_iter = storage. iter_mut_with_bitset_optional ( bitset) ;
470- assert_eq ! ( comp_mut_iter. next( ) , Some ( Some ( & mut a) ) ) ;
471-
472- entities. kill ( e) ;
473- }
474- }
475301}
0 commit comments