conversation_api/execution/
id.rs1use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7macro_rules! string_id {
8 ($name:ident) => {
9 #[doc = concat!("Stable identifier for `", stringify!($name), "` values.")]
10 #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
11 #[serde(transparent)]
12 pub struct $name(String);
13
14 impl $name {
15 #[must_use]
17 pub fn new(value: impl Into<String>) -> Self {
18 Self(value.into())
19 }
20
21 #[must_use]
23 pub fn as_str(&self) -> &str {
24 &self.0
25 }
26 }
27
28 impl From<String> for $name {
29 fn from(value: String) -> Self {
30 Self(value)
31 }
32 }
33
34 impl From<&str> for $name {
35 fn from(value: &str) -> Self {
36 Self(value.to_owned())
37 }
38 }
39
40 impl fmt::Display for $name {
41 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
42 formatter.write_str(&self.0)
43 }
44 }
45 };
46}
47
48string_id!(TenantId);
49string_id!(ScopeId);
50string_id!(UserId);
51string_id!(ClientId);
52string_id!(ThreadId);
53string_id!(RunId);
54string_id!(OperationId);
55string_id!(ActionId);
56string_id!(EventId);
57string_id!(MessageId);