use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Display},
str::FromStr,
};
use ulid::Ulid;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
)]
#[serde(transparent)]
pub struct AgentId(pub Ulid);
impl AgentId {
pub fn new() -> Self {
Self(Ulid::new())
}
pub const fn nil() -> Self {
Self(Ulid::nil())
}
pub fn is_nil(&self) -> bool {
self.0.is_nil()
}
}
impl Display for AgentId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}
impl FromStr for AgentId {
type Err = ulid::DecodeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ulid::from_str(s).map(Self)
}
}