Skip to main content

agent_migrate_core/transaction/
snapshot.rs

1use std::fmt;
2use std::str::FromStr;
3
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
8#[serde(transparent)]
9pub struct SnapshotId(Uuid);
10
11impl SnapshotId {
12    #[must_use]
13    pub fn new() -> Self {
14        Self(Uuid::new_v4())
15    }
16}
17
18impl Default for SnapshotId {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl fmt::Display for SnapshotId {
25    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
26        self.0.fmt(formatter)
27    }
28}
29
30impl FromStr for SnapshotId {
31    type Err = uuid::Error;
32
33    fn from_str(value: &str) -> Result<Self, Self::Err> {
34        Uuid::parse_str(value).map(Self)
35    }
36}