use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct AuditId(String);
impl AuditId {
pub fn new(value: impl Into<String>) -> Self {
AuditId(value.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn into_string(self) -> String {
self.0
}
}
impl fmt::Display for AuditId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl From<String> for AuditId {
fn from(value: String) -> Self {
AuditId(value)
}
}
impl From<&str> for AuditId {
fn from(value: &str) -> Self {
AuditId(value.to_owned())
}
}
impl From<&String> for AuditId {
fn from(value: &String) -> Self {
AuditId(value.clone())
}
}
impl From<uuid::Uuid> for AuditId {
fn from(value: uuid::Uuid) -> Self {
AuditId(value.to_string())
}
}
macro_rules! impl_from_int {
($($t:ty),*) => {
$(
impl From<$t> for AuditId {
fn from(value: $t) -> Self {
AuditId(value.to_string())
}
}
)*
};
}
impl_from_int!(
i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize
);