use serde::{Deserialize, Serialize}; use uuid::Uuid; macro_rules! id_type { ($name:ident) => { #[derive( Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, )] #[serde(transparent)] pub struct $name(pub Uuid); impl $name { #[must_use] pub fn new() -> Self { Self(Uuid::new_v4()) } #[must_use] pub fn into_inner(self) -> Uuid { self.0 } } impl Default for $name { fn default() -> Self { Self::new() } } impl From for $name { fn from(u: Uuid) -> Self { Self(u) } } impl From<$name> for Uuid { fn from(id: $name) -> Self { id.0 } } impl std::fmt::Display for $name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } }; } id_type!(ScriptId); id_type!(ExecutionId); id_type!(RequestId); id_type!(AdminUserId);