1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::fmt::{Display, Formatter, Result};
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct NodeId(pub u32);
impl Display for NodeId {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "NID({})", self.0)
}
}
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct ServiceId {
pub node_id: NodeId,
pub local_service_id: LocalServiceId,
}
impl Display for ServiceId {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "SID({}:{})", self.node_id.0, self.local_service_id.0)
}
}
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct LocalServiceId(pub u32);
impl LocalServiceId {
#[inline]
pub fn to_global(self, node_id: NodeId) -> ServiceId {
ServiceId {
node_id,
local_service_id: self,
}
}
}
impl Display for LocalServiceId {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "LID({})", self.0)
}
}