1use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7macro_rules! id_newtype {
9 ($name:ident, $doc:literal) => {
10 #[doc = $doc]
11 #[derive(
16 Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
17 )]
18 #[repr(transparent)]
19 pub struct $name(u64);
20
21 impl $name {
22 #[must_use]
28 pub const fn new(value: u64) -> Self {
29 Self(value)
30 }
31
32 #[must_use]
38 pub const fn get(self) -> u64 {
39 self.0
40 }
41
42 #[must_use]
48 pub const fn checked_next(self) -> Option<Self> {
49 match self.0.checked_add(1) {
50 Some(value) => Some(Self(value)),
51 None => None,
52 }
53 }
54 }
55
56 impl fmt::Display for $name {
57 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
58 write!(formatter, "{}", self.0)
59 }
60 }
61 };
62}
63
64id_newtype!(ElementId, "Stable canonical element identifier.");
65id_newtype!(RelationId, "Stable canonical relation identifier.");
66id_newtype!(IncidenceId, "Stable canonical incidence identifier.");
67id_newtype!(RoleId, "Stable canonical structural role identifier.");
68id_newtype!(LabelId, "Stable catalog label identifier.");
69id_newtype!(RelationTypeId, "Stable catalog relation-type identifier.");
70id_newtype!(PropertyKeyId, "Stable catalog property-key identifier.");
71id_newtype!(ProjectionId, "Stable catalog projection identifier.");
72id_newtype!(IndexId, "Stable catalog index identifier.");
73id_newtype!(CommitSeq, "Monotonic committed transaction sequence.");
74id_newtype!(TransactionId, "Monotonic writer transaction identifier.");
75id_newtype!(
76 CheckpointGeneration,
77 "Immutable checkpoint generation identifier."
78);