clay-borg/crates/cb-kernel/src/ids.rs

45 lines
1.1 KiB
Rust

//! Canonical identifiers (GameKernel §2.1): newtyped, copyable, ordered.
use serde::{Deserialize, Serialize};
macro_rules! id_type {
($(#[$doc:meta])* $name:ident($inner:ty)) => {
$(#[$doc])*
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
#[serde(transparent)]
pub struct $name(pub $inner);
impl core::fmt::Display for $name {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.0)
}
}
};
}
id_type!(
/// A single game instance.
GameId(u64)
);
id_type!(
/// Seat index within a game (0-based).
PlayerId(u8)
);
id_type!(
/// Semantic entity: problem, token, relation, card.
EntityId(u32)
);
id_type!(
/// Client-assigned command identifier for idempotency (GameKernel K2).
CommandId(u64)
);
id_type!(
/// Monotonic per-game event sequence number (GameKernel K4).
EventSeq(u64)
);
id_type!(
/// Deterministic game seed (GameKernel K5).
Seed(u64)
);