icentral_nodeid/
nodeid.rs

1crate::ix!();
2
3#[derive(Clone,Copy,PartialEq,PartialOrd,Eq,Ord,Hash)] 
4pub struct NodeId(usize);
5
6impl NodeId {
7
8    pub fn zero() -> Self {
9        Self(0)
10    }
11
12    pub fn bad() -> Self {
13        Self(usize::MAX)
14    }
15
16    pub fn val(&self) -> usize {
17        self.0
18    }
19}
20
21impl fmt::Display for NodeId {
22    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23        write!(f, "Node{}", self.0)
24    }
25}
26
27impl fmt::Debug for NodeId {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        write!(f, "Node{}", self.0)
30    }
31}
32
33impl From<usize> for NodeId {
34    fn from(x: usize) -> NodeId {
35        NodeId(x)
36    }
37}
38
39impl Default for NodeId {
40    fn default() -> Self {
41        Self::bad()
42    }
43}
44
45#[macro_export] macro_rules! nodeid {
46    ($id:expr) => {
47        NodeId::from($id)
48    }
49}