mina_node_testing/cluster/
node_id.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Copy)]
6pub struct ClusterNodeId(usize);
7
8impl ClusterNodeId {
9    pub fn new_unchecked(i: usize) -> Self {
10        Self(i)
11    }
12
13    pub fn index(self) -> usize {
14        self.0
15    }
16}
17
18impl fmt::Display for ClusterNodeId {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        write!(f, "{}", self.0)
21    }
22}
23
24impl From<ClusterNodeId> for u64 {
25    fn from(value: ClusterNodeId) -> Self {
26        value.0 as u64
27    }
28}
29
30impl From<ClusterNodeId> for usize {
31    fn from(value: ClusterNodeId) -> Self {
32        value.0
33    }
34}
35
36#[derive(Serialize, Deserialize, Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Copy)]
37pub struct ClusterOcamlNodeId(usize);
38
39impl ClusterOcamlNodeId {
40    pub fn new_unchecked(i: usize) -> Self {
41        Self(i)
42    }
43
44    pub fn index(self) -> usize {
45        self.0
46    }
47}
48
49impl fmt::Display for ClusterOcamlNodeId {
50    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
51        write!(f, "ocaml_{}", self.0)
52    }
53}
54
55impl From<ClusterOcamlNodeId> for u64 {
56    fn from(value: ClusterOcamlNodeId) -> Self {
57        value.0 as u64
58    }
59}
60
61impl From<ClusterOcamlNodeId> for usize {
62    fn from(value: ClusterOcamlNodeId) -> Self {
63        value.0
64    }
65}