Skip to main content

dodb_core/
identifiers.rs

1use std::fmt;
2
3macro_rules! integer_id {
4    ($(#[$meta:meta])* $name:ident) => {
5        $(#[$meta])*
6        #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
7        pub struct $name(u64);
8
9        impl $name {
10            pub const ZERO: Self = Self(0);
11
12            pub const fn new(value: u64) -> Self {
13                Self(value)
14            }
15
16            pub const fn get(self) -> u64 {
17                self.0
18            }
19        }
20
21        impl fmt::Display for $name {
22            fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
23                self.0.fmt(formatter)
24            }
25        }
26    };
27}
28
29integer_id!(
30    /// Tenant identity. It is deliberately distinct from [`ShardId`].
31    TenantId
32);
33integer_id!(
34    /// Physical shard identity. It is deliberately distinct from [`TenantId`].
35    ShardId
36);
37integer_id!(
38    /// Fencing/ownership epoch for a shard.
39    ShardEpoch
40);
41integer_id!(
42    /// Fixed-size storage page identity.
43    PageId
44);
45integer_id!(
46    /// Commit/log sequence number. A committed document revision is based on this value.
47    Lsn
48);
49integer_id!(
50    /// Transaction identity.
51    TxnId
52);
53integer_id!(
54    /// Last committed state-transition identifier for one document key.
55    Revision
56);