summaryrefslogtreecommitdiff
path: root/ecs/src/uid.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ecs/src/uid.rs')
-rw-r--r--ecs/src/uid.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/ecs/src/uid.rs b/ecs/src/uid.rs
index bcef73e..c3ed85b 100644
--- a/ecs/src/uid.rs
+++ b/ecs/src/uid.rs
@@ -32,22 +32,30 @@ impl Uid
let id = NEXT.fetch_add(1, Ordering::Relaxed);
Self {
- inner: ID_BITS.field_prep(id as u64) | KIND_BITS.field_prep(kind as u64),
+ inner: ID_BITS.field_prep(u64::from(id)) | KIND_BITS.field_prep(kind as u64),
}
}
#[must_use]
pub fn id(&self) -> u32
{
- self.inner.field_get(ID_BITS) as u32
+ let Ok(id) = u32::try_from(self.inner.field_get(ID_BITS)) else {
+ unreachable!("Uid id does not fit in u32");
+ };
+
+ id
}
#[must_use]
pub fn kind(&self) -> Kind
{
+ let Ok(kind) = u8::try_from(self.inner.field_get(KIND_BITS)) else {
+ unreachable!("Uid kind does not fit in u8");
+ };
+
// SAFETY: The kind bits cannot be invalid since they are set using the Kind enum
// in the new_unique function
- unsafe { transmute(self.inner.field_get(KIND_BITS) as u8) }
+ unsafe { transmute::<u8, Kind>(kind) }
}
}