systemprompt_identifiers/
links.rs

1use crate::{DbValue, ToDbValue};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
7#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
8#[cfg_attr(feature = "sqlx", sqlx(transparent))]
9#[serde(transparent)]
10pub struct LinkId(String);
11
12impl LinkId {
13    pub fn new(id: impl Into<String>) -> Self {
14        Self(id.into())
15    }
16
17    pub fn generate() -> Self {
18        Self(uuid::Uuid::new_v4().to_string())
19    }
20
21    pub fn as_str(&self) -> &str {
22        &self.0
23    }
24}
25
26impl fmt::Display for LinkId {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        write!(f, "{}", self.0)
29    }
30}
31
32impl From<String> for LinkId {
33    fn from(s: String) -> Self {
34        Self(s)
35    }
36}
37
38impl From<&str> for LinkId {
39    fn from(s: &str) -> Self {
40        Self(s.to_string())
41    }
42}
43
44impl AsRef<str> for LinkId {
45    fn as_ref(&self) -> &str {
46        &self.0
47    }
48}
49
50impl ToDbValue for LinkId {
51    fn to_db_value(&self) -> DbValue {
52        DbValue::String(self.0.clone())
53    }
54}
55
56impl ToDbValue for &LinkId {
57    fn to_db_value(&self) -> DbValue {
58        DbValue::String(self.0.clone())
59    }
60}
61
62#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
63#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
64#[cfg_attr(feature = "sqlx", sqlx(transparent))]
65#[serde(transparent)]
66pub struct CampaignId(String);
67
68impl CampaignId {
69    pub fn new(id: impl Into<String>) -> Self {
70        Self(id.into())
71    }
72
73    pub fn as_str(&self) -> &str {
74        &self.0
75    }
76}
77
78impl fmt::Display for CampaignId {
79    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80        write!(f, "{}", self.0)
81    }
82}
83
84impl From<String> for CampaignId {
85    fn from(s: String) -> Self {
86        Self(s)
87    }
88}
89
90impl From<&str> for CampaignId {
91    fn from(s: &str) -> Self {
92        Self(s.to_string())
93    }
94}
95
96impl AsRef<str> for CampaignId {
97    fn as_ref(&self) -> &str {
98        &self.0
99    }
100}
101
102impl ToDbValue for CampaignId {
103    fn to_db_value(&self) -> DbValue {
104        DbValue::String(self.0.clone())
105    }
106}
107
108impl ToDbValue for &CampaignId {
109    fn to_db_value(&self) -> DbValue {
110        DbValue::String(self.0.clone())
111    }
112}
113
114#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
115#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
116#[cfg_attr(feature = "sqlx", sqlx(transparent))]
117#[serde(transparent)]
118pub struct LinkClickId(String);
119
120impl LinkClickId {
121    pub fn new(id: impl Into<String>) -> Self {
122        Self(id.into())
123    }
124
125    pub fn generate() -> Self {
126        Self(uuid::Uuid::new_v4().to_string())
127    }
128
129    pub fn as_str(&self) -> &str {
130        &self.0
131    }
132}
133
134impl fmt::Display for LinkClickId {
135    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136        write!(f, "{}", self.0)
137    }
138}
139
140impl From<String> for LinkClickId {
141    fn from(s: String) -> Self {
142        Self(s)
143    }
144}
145
146impl From<&str> for LinkClickId {
147    fn from(s: &str) -> Self {
148        Self(s.to_string())
149    }
150}
151
152impl AsRef<str> for LinkClickId {
153    fn as_ref(&self) -> &str {
154        &self.0
155    }
156}
157
158impl ToDbValue for LinkClickId {
159    fn to_db_value(&self) -> DbValue {
160        DbValue::String(self.0.clone())
161    }
162}
163
164impl ToDbValue for &LinkClickId {
165    fn to_db_value(&self) -> DbValue {
166        DbValue::String(self.0.clone())
167    }
168}