Skip to main content

maple_runtime/types/
ids.rs

1//! Identity types for MAPLE Resonance Runtime
2
3use serde::{Deserialize, Serialize};
4use std::fmt;
5use uuid::Uuid;
6
7/// Unique identifier for a Resonator
8///
9/// NOT a UUID in the traditional sense - represents persistent identity
10/// that survives restarts, migrations, and network partitions.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
12pub struct ResonatorId(Uuid);
13
14impl ResonatorId {
15    pub fn new() -> Self {
16        Self(Uuid::new_v4())
17    }
18
19    pub fn from_bytes(bytes: [u8; 16]) -> Self {
20        Self(Uuid::from_bytes(bytes))
21    }
22
23    pub fn as_bytes(&self) -> &[u8; 16] {
24        self.0.as_bytes()
25    }
26}
27
28impl Default for ResonatorId {
29    fn default() -> Self {
30        Self::new()
31    }
32}
33
34impl fmt::Display for ResonatorId {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        write!(f, "resonator:{}", self.0)
37    }
38}
39
40/// Unique identifier for a coupling relationship
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
42pub struct CouplingId(Uuid);
43
44impl CouplingId {
45    pub fn generate() -> Self {
46        Self(Uuid::new_v4())
47    }
48}
49
50impl fmt::Display for CouplingId {
51    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52        write!(f, "coupling:{}", self.0)
53    }
54}
55
56/// Unique identifier for a commitment
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
58pub struct CommitmentId(Uuid);
59
60impl CommitmentId {
61    pub fn generate() -> Self {
62        Self(Uuid::new_v4())
63    }
64}
65
66impl fmt::Display for CommitmentId {
67    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68        write!(f, "commitment:{}", self.0)
69    }
70}
71
72/// Unique identifier for a temporal anchor
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
74pub struct AnchorId(Uuid);
75
76impl AnchorId {
77    pub fn generate() -> Self {
78        Self(Uuid::new_v4())
79    }
80}
81
82impl fmt::Display for AnchorId {
83    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84        write!(f, "anchor:{}", self.0)
85    }
86}
87
88/// Unique identifier for an allocation token
89#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
90pub struct AllocationToken(Uuid);
91
92impl AllocationToken {
93    pub fn new(_resonator: ResonatorId, _amount: u64) -> Self {
94        Self(Uuid::new_v4())
95    }
96}