@@ -455,9 +455,9 @@ impl Hash for Entity {
455455}
456456
457457impl Entity {
458- /// Constructs an [`Entity`] from a raw `row` value and a non-zero ` generation` value .
458+ /// Creates a new instance with the given index and generation.
459459 #[ inline( always) ]
460- pub const fn from_raw_and_generation ( row : EntityRow , generation : EntityGeneration ) -> Entity {
460+ pub const fn from_row_and_generation ( row : EntityRow , generation : EntityGeneration ) -> Entity {
461461 Self { row, generation }
462462 }
463463
@@ -495,7 +495,7 @@ impl Entity {
495495 /// }
496496 /// }
497497 /// ```
498- pub const PLACEHOLDER : Self = Self :: from_raw ( EntityRow :: PLACEHOLDER ) ;
498+ pub const PLACEHOLDER : Self = Self :: from_row ( EntityRow :: PLACEHOLDER ) ;
499499
500500 /// Creates a new entity ID with the specified `row` and a generation of 1.
501501 ///
@@ -510,17 +510,17 @@ impl Entity {
510510 /// `Entity` lines up between instances, but instead insert a secondary identifier as
511511 /// a component.
512512 #[ inline( always) ]
513- pub const fn from_raw ( row : EntityRow ) -> Entity {
514- Self :: from_raw_and_generation ( row, EntityGeneration :: FIRST )
513+ pub const fn from_row ( row : EntityRow ) -> Entity {
514+ Self :: from_row_and_generation ( row, EntityGeneration :: FIRST )
515515 }
516516
517- /// This is equivalent to [`from_raw `](Self::from_raw ) except that it takes a `u32` instead of an [`EntityRow`].
517+ /// This is equivalent to [`from_row `](Self::from_row ) except that it takes a `u32` instead of an [`EntityRow`].
518518 ///
519519 /// Returns `None` if the row is `u32::MAX`.
520520 #[ inline( always) ]
521521 pub const fn from_raw_u32 ( row : u32 ) -> Option < Entity > {
522522 match NonMaxU32 :: new ( row) {
523- Some ( row) => Some ( Self :: from_raw ( EntityRow :: new ( row) ) ) ,
523+ Some ( row) => Some ( Self :: from_row ( EntityRow :: new ( row) ) ) ,
524524 None => None ,
525525 }
526526 }
@@ -657,7 +657,7 @@ impl SparseSetIndex for Entity {
657657
658658 #[ inline]
659659 fn get_sparse_set_index ( value : usize ) -> Self {
660- Entity :: from_raw ( EntityRow :: get_sparse_set_index ( value) )
660+ Entity :: from_row ( EntityRow :: get_sparse_set_index ( value) )
661661 }
662662}
663663
@@ -680,13 +680,13 @@ impl<'a> Iterator for ReserveEntitiesIterator<'a> {
680680 self . freelist_indices
681681 . next ( )
682682 . map ( |& row| {
683- Entity :: from_raw_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
683+ Entity :: from_row_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
684684 } )
685685 . or_else ( || {
686686 self . new_indices . next ( ) . map ( |index| {
687687 // SAFETY: This came from an exclusive range so the max can't be hit.
688688 let row = unsafe { EntityRow :: new ( NonMaxU32 :: new_unchecked ( index) ) } ;
689- Entity :: from_raw ( row)
689+ Entity :: from_row ( row)
690690 } )
691691 } )
692692 }
@@ -833,7 +833,7 @@ impl Entities {
833833 if n > 0 {
834834 // Allocate from the freelist.
835835 let row = self . pending [ ( n - 1 ) as usize ] ;
836- Entity :: from_raw_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
836+ Entity :: from_row_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
837837 } else {
838838 // Grab a new ID, outside the range of `meta.len()`. `flush()` must
839839 // eventually be called to make it valid.
@@ -846,7 +846,7 @@ impl Entities {
846846 }
847847 // SAFETY: We just checked the bounds
848848 let row = unsafe { EntityRow :: new ( NonMaxU32 :: new_unchecked ( raw as u32 ) ) } ;
849- Entity :: from_raw ( row)
849+ Entity :: from_row ( row)
850850 }
851851 }
852852
@@ -864,14 +864,14 @@ impl Entities {
864864 if let Some ( row) = self . pending . pop ( ) {
865865 let new_free_cursor = self . pending . len ( ) as IdCursor ;
866866 * self . free_cursor . get_mut ( ) = new_free_cursor;
867- Entity :: from_raw_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
867+ Entity :: from_row_and_generation ( row, self . meta [ row. index ( ) as usize ] . generation )
868868 } else {
869869 let index = u32:: try_from ( self . meta . len ( ) )
870870 . ok ( )
871871 . and_then ( NonMaxU32 :: new)
872872 . expect ( "too many entities" ) ;
873873 self . meta . push ( EntityMeta :: EMPTY ) ;
874- Entity :: from_raw ( EntityRow :: new ( index) )
874+ Entity :: from_row ( EntityRow :: new ( index) )
875875 }
876876 }
877877
@@ -1012,14 +1012,14 @@ impl Entities {
10121012 pub fn resolve_from_id ( & self , row : EntityRow ) -> Option < Entity > {
10131013 let idu = row. index ( ) as usize ;
10141014 if let Some ( & EntityMeta { generation, .. } ) = self . meta . get ( idu) {
1015- Some ( Entity :: from_raw_and_generation ( row, generation) )
1015+ Some ( Entity :: from_row_and_generation ( row, generation) )
10161016 } else {
10171017 // `id` is outside of the meta list - check whether it is reserved but not yet flushed.
10181018 let free_cursor = self . free_cursor . load ( Ordering :: Relaxed ) ;
10191019 // If this entity was manually created, then free_cursor might be positive
10201020 // Returning None handles that case correctly
10211021 let num_pending = usize:: try_from ( -free_cursor) . ok ( ) ?;
1022- ( idu < self . meta . len ( ) + num_pending) . then_some ( Entity :: from_raw ( row) )
1022+ ( idu < self . meta . len ( ) + num_pending) . then_some ( Entity :: from_row ( row) )
10231023 }
10241024 }
10251025
@@ -1058,7 +1058,7 @@ impl Entities {
10581058 // SAFETY: the index is less than the meta length, which can not exceeded u32::MAX
10591059 let row = EntityRow :: new ( unsafe { NonMaxU32 :: new_unchecked ( index as u32 ) } ) ;
10601060 init (
1061- Entity :: from_raw_and_generation ( row, meta. generation ) ,
1061+ Entity :: from_row_and_generation ( row, meta. generation ) ,
10621062 & mut meta. location ,
10631063 ) ;
10641064 meta. spawned_or_despawned = SpawnedOrDespawned { by, tick } ;
@@ -1071,7 +1071,7 @@ impl Entities {
10711071 for row in self . pending . drain ( new_free_cursor..) {
10721072 let meta = & mut self . meta [ row. index ( ) as usize ] ;
10731073 init (
1074- Entity :: from_raw_and_generation ( row, meta. generation ) ,
1074+ Entity :: from_row_and_generation ( row, meta. generation ) ,
10751075 & mut meta. location ,
10761076 ) ;
10771077 meta. spawned_or_despawned = SpawnedOrDespawned { by, tick } ;
@@ -1333,7 +1333,7 @@ mod tests {
13331333 let r = EntityRow :: from_raw_u32 ( 0xDEADBEEF ) . unwrap ( ) ;
13341334 assert_eq ! ( EntityRow :: from_bits( r. to_bits( ) ) , r) ;
13351335
1336- let e = Entity :: from_raw_and_generation (
1336+ let e = Entity :: from_row_and_generation (
13371337 EntityRow :: from_raw_u32 ( 0xDEADBEEF ) . unwrap ( ) ,
13381338 EntityGeneration :: from_bits ( 0x5AADF00D ) ,
13391339 ) ;
@@ -1373,15 +1373,15 @@ mod tests {
13731373
13741374 #[ test]
13751375 fn entity_const ( ) {
1376- const C1 : Entity = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1376+ const C1 : Entity = Entity :: from_row ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
13771377 assert_eq ! ( 42 , C1 . index( ) ) ;
13781378 assert_eq ! ( 0 , C1 . generation( ) . to_bits( ) ) ;
13791379
13801380 const C2 : Entity = Entity :: from_bits ( 0x0000_00ff_0000_00cc ) ;
13811381 assert_eq ! ( !0x0000_00cc , C2 . index( ) ) ;
13821382 assert_eq ! ( 0x0000_00ff , C2 . generation( ) . to_bits( ) ) ;
13831383
1384- const C3 : u32 = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 33 ) . unwrap ( ) ) . index ( ) ;
1384+ const C3 : u32 = Entity :: from_row ( EntityRow :: from_raw_u32 ( 33 ) . unwrap ( ) ) . index ( ) ;
13851385 assert_eq ! ( 33 , C3 ) ;
13861386
13871387 const C4 : u32 = Entity :: from_bits ( 0x00dd_00ff_1111_1111 )
@@ -1425,41 +1425,41 @@ mod tests {
14251425 ) ]
14261426 fn entity_comparison ( ) {
14271427 assert_eq ! (
1428- Entity :: from_raw_and_generation (
1428+ Entity :: from_row_and_generation (
14291429 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14301430 EntityGeneration :: from_bits( 456 )
14311431 ) ,
1432- Entity :: from_raw_and_generation (
1432+ Entity :: from_row_and_generation (
14331433 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14341434 EntityGeneration :: from_bits( 456 )
14351435 )
14361436 ) ;
14371437 assert_ne ! (
1438- Entity :: from_raw_and_generation (
1438+ Entity :: from_row_and_generation (
14391439 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14401440 EntityGeneration :: from_bits( 789 )
14411441 ) ,
1442- Entity :: from_raw_and_generation (
1442+ Entity :: from_row_and_generation (
14431443 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14441444 EntityGeneration :: from_bits( 456 )
14451445 )
14461446 ) ;
14471447 assert_ne ! (
1448- Entity :: from_raw_and_generation (
1448+ Entity :: from_row_and_generation (
14491449 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14501450 EntityGeneration :: from_bits( 456 )
14511451 ) ,
1452- Entity :: from_raw_and_generation (
1452+ Entity :: from_row_and_generation (
14531453 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14541454 EntityGeneration :: from_bits( 789 )
14551455 )
14561456 ) ;
14571457 assert_ne ! (
1458- Entity :: from_raw_and_generation (
1458+ Entity :: from_row_and_generation (
14591459 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14601460 EntityGeneration :: from_bits( 456 )
14611461 ) ,
1462- Entity :: from_raw_and_generation (
1462+ Entity :: from_row_and_generation (
14631463 EntityRow :: from_raw_u32( 456 ) . unwrap( ) ,
14641464 EntityGeneration :: from_bits( 123 )
14651465 )
@@ -1468,93 +1468,93 @@ mod tests {
14681468 // ordering is by generation then by index
14691469
14701470 assert ! (
1471- Entity :: from_raw_and_generation (
1471+ Entity :: from_row_and_generation (
14721472 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14731473 EntityGeneration :: from_bits( 456 )
1474- ) >= Entity :: from_raw_and_generation (
1474+ ) >= Entity :: from_row_and_generation (
14751475 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14761476 EntityGeneration :: from_bits( 456 )
14771477 )
14781478 ) ;
14791479 assert ! (
1480- Entity :: from_raw_and_generation (
1480+ Entity :: from_row_and_generation (
14811481 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14821482 EntityGeneration :: from_bits( 456 )
1483- ) <= Entity :: from_raw_and_generation (
1483+ ) <= Entity :: from_row_and_generation (
14841484 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14851485 EntityGeneration :: from_bits( 456 )
14861486 )
14871487 ) ;
14881488 assert ! (
1489- !( Entity :: from_raw_and_generation (
1489+ !( Entity :: from_row_and_generation (
14901490 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14911491 EntityGeneration :: from_bits( 456 )
1492- ) < Entity :: from_raw_and_generation (
1492+ ) < Entity :: from_row_and_generation (
14931493 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
14941494 EntityGeneration :: from_bits( 456 )
14951495 ) )
14961496 ) ;
14971497 assert ! (
1498- !( Entity :: from_raw_and_generation (
1498+ !( Entity :: from_row_and_generation (
14991499 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
15001500 EntityGeneration :: from_bits( 456 )
1501- ) > Entity :: from_raw_and_generation (
1501+ ) > Entity :: from_row_and_generation (
15021502 EntityRow :: from_raw_u32( 123 ) . unwrap( ) ,
15031503 EntityGeneration :: from_bits( 456 )
15041504 ) )
15051505 ) ;
15061506
15071507 assert ! (
1508- Entity :: from_raw_and_generation (
1508+ Entity :: from_row_and_generation (
15091509 EntityRow :: from_raw_u32( 9 ) . unwrap( ) ,
15101510 EntityGeneration :: from_bits( 1 )
1511- ) < Entity :: from_raw_and_generation (
1511+ ) < Entity :: from_row_and_generation (
15121512 EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
15131513 EntityGeneration :: from_bits( 9 )
15141514 )
15151515 ) ;
15161516 assert ! (
1517- Entity :: from_raw_and_generation (
1517+ Entity :: from_row_and_generation (
15181518 EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
15191519 EntityGeneration :: from_bits( 9 )
1520- ) > Entity :: from_raw_and_generation (
1520+ ) > Entity :: from_row_and_generation (
15211521 EntityRow :: from_raw_u32( 9 ) . unwrap( ) ,
15221522 EntityGeneration :: from_bits( 1 )
15231523 )
15241524 ) ;
15251525
15261526 assert ! (
1527- Entity :: from_raw_and_generation (
1527+ Entity :: from_row_and_generation (
15281528 EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
15291529 EntityGeneration :: from_bits( 1 )
1530- ) > Entity :: from_raw_and_generation (
1530+ ) > Entity :: from_row_and_generation (
15311531 EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
15321532 EntityGeneration :: from_bits( 1 )
15331533 )
15341534 ) ;
15351535 assert ! (
1536- Entity :: from_raw_and_generation (
1536+ Entity :: from_row_and_generation (
15371537 EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
15381538 EntityGeneration :: from_bits( 1 )
1539- ) >= Entity :: from_raw_and_generation (
1539+ ) >= Entity :: from_row_and_generation (
15401540 EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
15411541 EntityGeneration :: from_bits( 1 )
15421542 )
15431543 ) ;
15441544 assert ! (
1545- Entity :: from_raw_and_generation (
1545+ Entity :: from_row_and_generation (
15461546 EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
15471547 EntityGeneration :: from_bits( 2 )
1548- ) < Entity :: from_raw_and_generation (
1548+ ) < Entity :: from_row_and_generation (
15491549 EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
15501550 EntityGeneration :: from_bits( 2 )
15511551 )
15521552 ) ;
15531553 assert ! (
1554- Entity :: from_raw_and_generation (
1554+ Entity :: from_row_and_generation (
15551555 EntityRow :: from_raw_u32( 2 ) . unwrap( ) ,
15561556 EntityGeneration :: from_bits( 2 )
1557- ) <= Entity :: from_raw_and_generation (
1557+ ) <= Entity :: from_row_and_generation (
15581558 EntityRow :: from_raw_u32( 1 ) . unwrap( ) ,
15591559 EntityGeneration :: from_bits( 2 )
15601560 )
@@ -1570,11 +1570,11 @@ mod tests {
15701570
15711571 let first_id = 0xC0FFEE << 8 ;
15721572 let first_hash =
1573- hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) ;
1573+ hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) ;
15741574
15751575 for i in 1 ..=255 {
15761576 let id = first_id + i;
1577- let hash = hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) ;
1577+ let hash = hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) ;
15781578 assert_eq ! ( first_hash. wrapping_sub( hash) as u32 , i) ;
15791579 }
15801580 }
@@ -1587,11 +1587,11 @@ mod tests {
15871587
15881588 let first_id = 0xC0FFEE ;
15891589 let first_hash =
1590- hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) >> 57 ;
1590+ hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( first_id) . unwrap ( ) ) ) >> 57 ;
15911591
15921592 for bit in 0 ..u32:: BITS {
15931593 let id = first_id ^ ( 1 << bit) ;
1594- let hash = hash. hash_one ( Entity :: from_raw ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) >> 57 ;
1594+ let hash = hash. hash_one ( Entity :: from_row ( EntityRow :: from_raw_u32 ( id) . unwrap ( ) ) ) >> 57 ;
15951595 assert_ne ! ( hash, first_hash) ;
15961596 }
15971597 }
@@ -1616,7 +1616,7 @@ mod tests {
16161616
16171617 #[ test]
16181618 fn entity_debug ( ) {
1619- let entity = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1619+ let entity = Entity :: from_row ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
16201620 let string = format ! ( "{entity:?}" ) ;
16211621 assert_eq ! ( string, "42v0" ) ;
16221622
@@ -1627,7 +1627,7 @@ mod tests {
16271627
16281628 #[ test]
16291629 fn entity_display ( ) {
1630- let entity = Entity :: from_raw ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
1630+ let entity = Entity :: from_row ( EntityRow :: from_raw_u32 ( 42 ) . unwrap ( ) ) ;
16311631 let string = format ! ( "{entity}" ) ;
16321632 assert_eq ! ( string, "42v0" ) ;
16331633
0 commit comments