rtm_core/models/
transaction_id.rs

1use std::num::ParseIntError;
2
3/// Represents a transaction id.
4#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
5#[repr(transparent)]
6#[must_use]
7pub struct TransactionId {
8    value: u32,
9}
10
11impl TransactionId {
12    #[must_use]
13    pub const fn as_u32(&self) -> u32 {
14        self.value
15    }
16}
17
18impl From<u32> for TransactionId {
19    fn from(value: u32) -> Self {
20        Self { value }
21    }
22}
23
24impl TryFrom<&str> for TransactionId {
25    type Error = ParseIntError;
26
27    fn try_from(value: &str) -> Result<Self, Self::Error> {
28        let value = value.parse::<u32>()?;
29        Ok(Self { value })
30    }
31}