use std::fmt; pub const INSTANCE_ID_MODULO: i32 = 1_000_000; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct GlobalId { pub class_id: i32, pub instance_id: i32, } impl GlobalId { pub const fn new(class_id: i32, instance_id: i32) -> Self { Self { class_id, instance_id, } } pub const fn from_global(global_id: i32) -> Self { Self { class_id: global_id / INSTANCE_ID_MODULO, instance_id: global_id % INSTANCE_ID_MODULO, } } pub const fn to_global(self) -> i32 { self.class_id * INSTANCE_ID_MODULO + self.instance_id } } impl fmt::Display for GlobalId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}:{}", self.class_id, self.instance_id) } }