use serde::{Deserialize, Serialize};
use std::fmt;
use ulid::Ulid;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct RevisionId(pub Ulid);
impl RevisionId {
pub fn new() -> Self {
Self(Ulid::new())
}
}
impl Default for RevisionId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for RevisionId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct DeploymentId(pub Ulid);
impl DeploymentId {
pub fn new() -> Self {
Self(Ulid::new())
}
}
impl Default for DeploymentId {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for DeploymentId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
macro_rules! string_id {
($(#[$meta:meta])* $name:ident) => {
$(#[$meta])*
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct $name(pub String);
impl $name {
pub fn new(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<String> for $name {
fn from(s: String) -> Self {
Self(s)
}
}
impl From<&str> for $name {
fn from(s: &str) -> Self {
Self(s.to_string())
}
}
};
}
string_id!(
BundleId
);
string_id!(
CustomerId
);
string_id!(
PackId
);
string_id!(
PartyId
);