Skip to main content

nodedb_types/id/
txn.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7/// Identifies a session transaction block. Keys the per-transaction staging
8/// overlay. Unique across concurrent sessions on a shard.
9#[derive(
10    Debug,
11    Clone,
12    Copy,
13    PartialEq,
14    Eq,
15    Hash,
16    Serialize,
17    Deserialize,
18    zerompk::ToMessagePack,
19    zerompk::FromMessagePack,
20    rkyv::Archive,
21    rkyv::Serialize,
22    rkyv::Deserialize,
23)]
24pub struct TxnId(u64);
25
26impl TxnId {
27    pub const fn new(id: u64) -> Self {
28        Self(id)
29    }
30
31    pub const fn as_u64(self) -> u64 {
32        self.0
33    }
34}
35
36impl fmt::Display for TxnId {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        write!(f, "txn:{}", self.0)
39    }
40}