summaryrefslogtreecommitdiff
path: root/ecs/src/uid.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-03-18 13:21:46 +0100
committerHampusM <hampus@hampusmat.com>2025-03-18 13:21:46 +0100
commit7a7d3a350b22b5555c27debff6fee4fc6100fa38 (patch)
tree9eb96f2563264f51691e2a06a7b95f8b39904d18 /ecs/src/uid.rs
parentee7c0cb713891ae480407f56823289f3fe3b9807 (diff)
refactor(ecs): fix Clippy lintsHEADmaster
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) }
}
}