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