#[derive(Debug)] pub struct IdempotencyKey(String); impl TryFrom for IdempotencyKey { type Error = String; fn try_from(value: String) -> Result { if value.is_empty() { return Err("The idempotency key cannot be empty.".into()); } let max_length = 50; if value.len() >= max_length { return Err("The idempotency key must be shorter than {max_length} characters.".into()); } Ok(Self(value)) } } impl From for String { fn from(value: IdempotencyKey) -> Self { value.0 } } impl AsRef for IdempotencyKey { fn as_ref(&self) -> &str { &self.0 } }