Skip to main content

manabrew_engine/
ids.rs

1use serde::{Deserialize, Serialize};
2
3/// Typed index into the card arena. Not a reference — just an index.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
5pub struct CardId(pub u32);
6
7/// Typed index into the player arena.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
9pub struct PlayerId(pub u32);
10
11impl CardId {
12    pub fn index(self) -> usize {
13        self.0 as usize
14    }
15}
16
17impl PlayerId {
18    pub fn index(self) -> usize {
19        self.0 as usize
20    }
21}
22
23impl std::fmt::Display for CardId {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        write!(f, "Card#{}", self.0)
26    }
27}
28
29impl std::fmt::Display for PlayerId {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        write!(f, "Player#{}", self.0)
32    }
33}