use std::{hash::Hash, sync::Arc};
#[derive(Debug, Clone, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct ActorId(Arc<str>);
impl ActorId {
#[must_use]
pub fn new(id: &str) -> Self {
Self(Arc::from(id))
}
#[inline]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl PartialEq for ActorId {
fn eq(&self, other: &Self) -> bool {
Arc::ptr_eq(&self.0, &other.0) || self.0 == other.0
}
}
impl Eq for ActorId {}
impl std::fmt::Display for ActorId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl Hash for ActorId {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
impl From<&str> for ActorId {
fn from(s: &str) -> Self {
Self::new(s)
}
}
impl From<String> for ActorId {
fn from(s: String) -> Self {
Self(Arc::from(s))
}
}
impl AsRef<str> for ActorId {
fn as_ref(&self) -> &str {
&self.0
}
}