use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
use super::CrdtError;
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct ReplicaId(String);
impl ReplicaId {
pub fn new(value: impl Into<String>) -> Result<Self, CrdtError> {
let value = value.into();
if value.is_empty() {
return Err(CrdtError::EmptyReplicaId);
}
Ok(Self(value))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl Display for ReplicaId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}