use serde::{Deserialize, Serialize};
use std::fmt;
macro_rules! typed_id {
($name:ident, $doc:expr) => {
#[doc = $doc]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
pub struct $name(pub String);
impl $name {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<&str> for $name {
fn from(s: &str) -> Self {
Self(s.to_owned())
}
}
impl From<String> for $name {
fn from(s: String) -> Self {
Self(s)
}
}
};
}
typed_id!(OperatorId, "Unique identifier for an operator.");
typed_id!(SessionId, "Unique identifier for a conversation session.");
typed_id!(WorkflowId, "Unique identifier for a workflow execution.");
typed_id!(ScopeId, "Unique identifier for a state scope.");