diff options
author | HampusM <hampus@hampusmat.com> | 2025-01-19 20:18:21 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2025-01-19 20:19:06 +0100 |
commit | 05d2d6bad38edc7973175dc917c86597bb8aa08d (patch) | |
tree | abebd6628ba69226e00e4b1efd3027e81ea76dc0 /ecs/src | |
parent | 8b14c97d4fa95efce095ae4e04d5dfee0b3b5b69 (diff) |
feat(ecs): make Uid Debug trait impl actually useful
Diffstat (limited to 'ecs/src')
-rw-r--r-- | ecs/src/uid.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/ecs/src/uid.rs b/ecs/src/uid.rs index 60167d3..bcef73e 100644 --- a/ecs/src/uid.rs +++ b/ecs/src/uid.rs @@ -1,3 +1,4 @@ +use std::fmt::{Debug, Formatter}; use std::mem::transmute; use std::sync::atomic::{AtomicU32, Ordering}; @@ -17,7 +18,7 @@ pub enum Kind } /// Unique entity/component ID. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Uid { inner: u64, @@ -36,6 +37,12 @@ impl Uid } #[must_use] + pub fn id(&self) -> u32 + { + self.inner.field_get(ID_BITS) as u32 + } + + #[must_use] pub fn kind(&self) -> Kind { // SAFETY: The kind bits cannot be invalid since they are set using the Kind enum @@ -43,3 +50,15 @@ impl Uid unsafe { transmute(self.inner.field_get(KIND_BITS) as u8) } } } + +impl Debug for Uid +{ + fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result + { + formatter + .debug_struct("Uid") + .field("id", &self.id()) + .field("kind", &self.kind()) + .finish_non_exhaustive() + } +} |