systemprompt_identifiers/
jobs.rs

1//! Job-related identifier types.
2
3use crate::{DbValue, ToDbValue};
4use serde::{Deserialize, Serialize};
5use std::fmt;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
9#[cfg_attr(feature = "sqlx", sqlx(transparent))]
10#[serde(transparent)]
11pub struct ScheduledJobId(String);
12
13impl ScheduledJobId {
14    pub fn new(id: impl Into<String>) -> Self {
15        Self(id.into())
16    }
17
18    pub fn generate() -> Self {
19        Self(uuid::Uuid::new_v4().to_string())
20    }
21
22    pub fn as_str(&self) -> &str {
23        &self.0
24    }
25}
26
27impl fmt::Display for ScheduledJobId {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        write!(f, "{}", self.0)
30    }
31}
32
33impl From<String> for ScheduledJobId {
34    fn from(s: String) -> Self {
35        Self(s)
36    }
37}
38
39impl From<&str> for ScheduledJobId {
40    fn from(s: &str) -> Self {
41        Self(s.to_string())
42    }
43}
44
45impl AsRef<str> for ScheduledJobId {
46    fn as_ref(&self) -> &str {
47        &self.0
48    }
49}
50
51impl ToDbValue for ScheduledJobId {
52    fn to_db_value(&self) -> DbValue {
53        DbValue::String(self.0.clone())
54    }
55}
56
57impl ToDbValue for &ScheduledJobId {
58    fn to_db_value(&self) -> DbValue {
59        DbValue::String(self.0.clone())
60    }
61}
62
63#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
64#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
65#[cfg_attr(feature = "sqlx", sqlx(transparent))]
66#[serde(transparent)]
67pub struct JobName(String);
68
69impl JobName {
70    pub fn new(name: impl Into<String>) -> Self {
71        Self(name.into())
72    }
73
74    pub fn as_str(&self) -> &str {
75        &self.0
76    }
77}
78
79impl fmt::Display for JobName {
80    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81        write!(f, "{}", self.0)
82    }
83}
84
85impl From<String> for JobName {
86    fn from(s: String) -> Self {
87        Self(s)
88    }
89}
90
91impl From<&str> for JobName {
92    fn from(s: &str) -> Self {
93        Self(s.to_string())
94    }
95}
96
97impl AsRef<str> for JobName {
98    fn as_ref(&self) -> &str {
99        &self.0
100    }
101}
102
103impl ToDbValue for JobName {
104    fn to_db_value(&self) -> DbValue {
105        DbValue::String(self.0.clone())
106    }
107}
108
109impl ToDbValue for &JobName {
110    fn to_db_value(&self) -> DbValue {
111        DbValue::String(self.0.clone())
112    }
113}