use super::utils;
use std::ops::Deref;
macro_rules! string_wrapper_impls {
($new_type:ident) => {
impl $new_type {
pub fn new<S>(inner: S) -> Self
where
S: Into<String>,
{
Self(inner.into())
}
}
impl Deref for $new_type {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl AsRef<str> for $new_type {
fn as_ref(&self) -> &str {
self.deref().as_ref()
}
}
impl AsRef<$new_type> for $new_type {
fn as_ref(&self) -> &$new_type {
&self
}
}
impl PartialEq<str> for $new_type {
fn eq(&self, other: &str) -> bool {
self.deref().eq(other)
}
}
};
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct JobId(String);
impl JobId {
pub fn random() -> Self {
Self(utils::gen_random_jid())
}
}
string_wrapper_impls!(JobId);
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct WorkerId(String);
impl WorkerId {
pub fn random() -> Self {
Self(utils::gen_random_wid())
}
}
string_wrapper_impls!(WorkerId);
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
pub struct BatchId(String);
string_wrapper_impls!(BatchId);
use serde_json::Value;
impl From<BatchId> for Value {
fn from(value: BatchId) -> Self {
value.0.into()
}
}