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