actionqueue_core/ids/
attempt_id.rs1use std::fmt::{Display, Formatter};
4use std::str::FromStr;
5
6use uuid::Uuid;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct AttemptId(Uuid);
15
16impl AttemptId {
17 pub fn new() -> Self {
19 AttemptId(Uuid::new_v4())
20 }
21
22 pub fn from_uuid(uuid: Uuid) -> Self {
24 AttemptId(uuid)
25 }
26
27 pub fn as_uuid(&self) -> &Uuid {
29 &self.0
30 }
31}
32
33impl Default for AttemptId {
34 fn default() -> Self {
35 Self::new()
36 }
37}
38
39impl FromStr for AttemptId {
40 type Err = uuid::Error;
41
42 fn from_str(s: &str) -> Result<Self, Self::Err> {
43 Uuid::from_str(s).map(AttemptId)
44 }
45}
46
47impl Display for AttemptId {
48 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49 write!(f, "{}", self.0)
50 }
51}