Skip to content

Commit a7680e3

Browse files
committed
Improve docs more, to_identifier helper method
1 parent c417105 commit a7680e3

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

crates/bevy_ecs/src/entity/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,13 @@ impl Entity {
267267
/// No particular structure is guaranteed for the returned bits.
268268
#[inline(always)]
269269
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)
271277
}
272278

273279
/// Reconstruct an `Entity` previously destructured with [`Entity::to_bits`].
@@ -329,7 +335,7 @@ impl Entity {
329335
/// given index has been reused (index, generation) pairs uniquely identify a given Entity.
330336
#[inline]
331337
pub const fn generation(self) -> u32 {
332-
Identifier::from_parts(self.index, self.generation).masked_high()
338+
self.to_identifier().masked_high()
333339
}
334340
}
335341

@@ -350,7 +356,7 @@ impl From<Entity> for Identifier {
350356
// Entity's layout is exactly the same as Identifier, therefore
351357
// this will remove any panic! path as we know Entity -> Identifier
352358
// conversions will never panic.
353-
Identifier::from_parts(value.index, value.generation)
359+
value.to_identifier()
354360
}
355361
}
356362

crates/bevy_ecs/src/identifier/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ pub(crate) mod masks;
1515

1616
/// A unified identifier for all entity and similar IDs.
1717
/// 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.
2019
#[derive(Debug, Clone, Copy)]
2120
// Alignment repr necessary to allow LLVM to better output
2221
// optimised codegen for `to_bits`, `PartialEq` and `Ord`.
@@ -32,8 +31,8 @@ pub struct Identifier {
3231
}
3332

3433
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.
3736
#[inline(always)]
3837
pub const fn new(
3938
low: u32,
@@ -56,10 +55,10 @@ impl Identifier {
5655
// SAFETY: The high value has been checked to ensure it is never
5756
// zero.
5857
unsafe {
59-
Ok(Self {
58+
Ok(Self::from_parts(
6059
low,
61-
high: NonZeroU32::new_unchecked(packed_high),
62-
})
60+
NonZeroU32::new_unchecked(packed_high),
61+
))
6362
}
6463
}
6564
}

0 commit comments

Comments
 (0)