1use core::fmt;
2use core::num::NonZeroU64;
3
4#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7pub struct NodeId(NonZeroU64);
8
9impl NodeId {
10 pub(crate) fn from_index(index: u64) -> Self {
11 let value = NonZeroU64::new(index).expect("node ids start at 1");
12 Self(value)
13 }
14
15 pub fn get(self) -> u64 {
17 self.0.get()
18 }
19}
20
21impl fmt::Debug for NodeId {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "NodeId({})", self.get())
24 }
25}
26
27#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30pub struct ScopeId(NonZeroU64);
31
32impl ScopeId {
33 pub(crate) fn from_index(index: u64) -> Self {
34 let value = NonZeroU64::new(index).expect("scope ids start at 1");
35 Self(value)
36 }
37
38 pub fn get(self) -> u64 {
40 self.0.get()
41 }
42}
43
44impl fmt::Debug for ScopeId {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 write!(f, "ScopeId({})", self.get())
47 }
48}
49
50#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
52#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
53pub struct OutputKey(NonZeroU64);
54
55impl OutputKey {
56 pub(crate) fn from_index(index: u64) -> Self {
57 let value = NonZeroU64::new(index).expect("output keys start at 1");
58 Self(value)
59 }
60
61 pub fn get(self) -> u64 {
63 self.0.get()
64 }
65}
66
67impl fmt::Debug for OutputKey {
68 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69 write!(f, "OutputKey({})", self.get())
70 }
71}
72
73#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
75#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
76pub struct Revision(u64);
77
78impl Revision {
79 pub const fn new(value: u64) -> Self {
81 Self(value)
82 }
83
84 pub const fn get(self) -> u64 {
86 self.0
87 }
88
89 pub(crate) const fn next(self) -> Self {
90 Self(self.0 + 1)
91 }
92}
93
94#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
96#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
97pub struct TransactionId(u64);
98
99impl TransactionId {
100 pub const fn new(value: u64) -> Self {
102 Self(value)
103 }
104
105 pub const fn get(self) -> u64 {
107 self.0
108 }
109
110 pub(crate) const fn next(self) -> Self {
111 Self(self.0 + 1)
112 }
113}