use serde::{Deserialize, Serialize};
use std::fmt;
macro_rules! typed_id {
($(#[$doc:meta])* $name:ident, $prefix:literal) => {
$(#[$doc])*
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct $name(String);
impl $name {
pub fn generate() -> Self {
Self(format!("{}_{}", $prefix, uuid::Uuid::now_v7()))
}
pub fn from_string(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl From<$name> for String {
fn from(id: $name) -> String {
id.0
}
}
};
}
typed_id!(
SourceId,
"src"
);
typed_id!(
FileId,
"file"
);
typed_id!(
ExtractionId,
"ext"
);
typed_id!(
ChunkId,
"chunk"
);
typed_id!(
JobId,
"job"
);
typed_id!(
ModelId,
"model"
);
typed_id!(
QueryId,
"query"
);
typed_id!(
EventId,
"evt"
);