systemprompt_identifiers/
task.rs1use 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 TaskId(String);
12
13impl TaskId {
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 TaskId {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "{}", self.0)
30 }
31}
32
33impl From<String> for TaskId {
34 fn from(s: String) -> Self {
35 Self(s)
36 }
37}
38
39impl From<&str> for TaskId {
40 fn from(s: &str) -> Self {
41 Self(s.to_string())
42 }
43}
44
45impl AsRef<str> for TaskId {
46 fn as_ref(&self) -> &str {
47 &self.0
48 }
49}
50
51impl ToDbValue for TaskId {
52 fn to_db_value(&self) -> DbValue {
53 DbValue::String(self.0.clone())
54 }
55}
56
57impl ToDbValue for &TaskId {
58 fn to_db_value(&self) -> DbValue {
59 DbValue::String(self.0.clone())
60 }
61}
62
63impl From<TaskId> for String {
64 fn from(id: TaskId) -> Self {
65 id.0
66 }
67}
68
69impl From<&TaskId> for String {
70 fn from(id: &TaskId) -> Self {
71 id.0.clone()
72 }
73}
74
75impl PartialEq<&str> for TaskId {
76 fn eq(&self, other: &&str) -> bool {
77 self.0 == *other
78 }
79}
80
81impl PartialEq<str> for TaskId {
82 fn eq(&self, other: &str) -> bool {
83 self.0 == other
84 }
85}
86
87impl std::borrow::Borrow<str> for TaskId {
88 fn borrow(&self) -> &str {
89 &self.0
90 }
91}