File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -267,7 +267,13 @@ impl Entity {
267
267
/// No particular structure is guaranteed for the returned bits.
268
268
#[ inline( always) ]
269
269
pub const fn to_bits ( self ) -> u64 {
270
- Identifier :: from_parts ( self . index , self . generation ) . to_bits ( )
270
+ self . to_identifier ( ) . to_bits ( )
271
+ }
272
+
273
+ /// Convert to an [`Identifier`].
274
+ #[ inline( always) ]
275
+ pub const fn to_identifier ( self ) -> Identifier {
276
+ Identifier :: from_parts ( self . index , self . generation )
271
277
}
272
278
273
279
/// Reconstruct an `Entity` previously destructured with [`Entity::to_bits`].
@@ -329,7 +335,7 @@ impl Entity {
329
335
/// given index has been reused (index, generation) pairs uniquely identify a given Entity.
330
336
#[ inline]
331
337
pub const fn generation ( self ) -> u32 {
332
- Identifier :: from_parts ( self . index , self . generation ) . masked_high ( )
338
+ self . to_identifier ( ) . masked_high ( )
333
339
}
334
340
}
335
341
@@ -350,7 +356,7 @@ impl From<Entity> for Identifier {
350
356
// Entity's layout is exactly the same as Identifier, therefore
351
357
// this will remove any panic! path as we know Entity -> Identifier
352
358
// conversions will never panic.
353
- Identifier :: from_parts ( value. index , value . generation )
359
+ value. to_identifier ( )
354
360
}
355
361
}
356
362
Original file line number Diff line number Diff line change @@ -15,8 +15,7 @@ pub(crate) mod masks;
15
15
16
16
/// A unified identifier for all entity and similar IDs.
17
17
/// Has the same size as a `u64` integer, but the layout is split between a 32-bit low
18
- /// segment, a 31-bit high segment, and the significant bit reserved as type flags to denote
19
- /// entity kinds.
18
+ /// segment, a 30-bit high segment, and the 2 most significant bits reserved as bit flags.
20
19
#[ derive( Debug , Clone , Copy ) ]
21
20
// Alignment repr necessary to allow LLVM to better output
22
21
// optimised codegen for `to_bits`, `PartialEq` and `Ord`.
@@ -32,8 +31,8 @@ pub struct Identifier {
32
31
}
33
32
34
33
impl Identifier {
35
- /// Construct a new [`Identifier`]. The `high` parameter is masked with the
36
- /// `kind` so to pack the high value and bit flags into the same field.
34
+ /// Construct a new [`Identifier`]. The `high` parameter is masked so to pack
35
+ /// the high value and bit flags into the same field.
37
36
#[ inline( always) ]
38
37
pub const fn new (
39
38
low : u32 ,
@@ -56,10 +55,10 @@ impl Identifier {
56
55
// SAFETY: The high value has been checked to ensure it is never
57
56
// zero.
58
57
unsafe {
59
- Ok ( Self {
58
+ Ok ( Self :: from_parts (
60
59
low,
61
- high : NonZeroU32 :: new_unchecked ( packed_high) ,
62
- } )
60
+ NonZeroU32 :: new_unchecked ( packed_high) ,
61
+ ) )
63
62
}
64
63
}
65
64
}
You can’t perform that action at this time.
0 commit comments