reddb_engine/storage/entity_id.rs
1//! Stable entity identity shared by storage and transaction tracking.
2
3use std::fmt;
4
5/// Unique identifier for any entity in the unified storage
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct EntityId(pub u64);
8
9impl EntityId {
10 /// Create a new entity ID
11 pub fn new(id: u64) -> Self {
12 Self(id)
13 }
14
15 /// Get the raw ID value
16 pub fn raw(&self) -> u64 {
17 self.0
18 }
19}
20
21impl fmt::Display for EntityId {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "e{}", self.0)
24 }
25}
26
27impl From<u64> for EntityId {
28 fn from(id: u64) -> Self {
29 Self(id)
30 }
31}