use std::{fmt, str::FromStr};
use crate::deploy::error::BadDeploy;
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct DexName(String);
impl DexName {
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl FromStr for DexName {
type Err = BadDeploy;
fn from_str(name: &str) -> Result<Self, Self::Err> {
let letters = name.bytes().all(|byte| byte.is_ascii_lowercase());
if !(2..=4).contains(&name.len()) || !letters {
return Err(BadDeploy::Name(name.to_owned()));
}
Ok(DexName(name.to_owned()))
}
}
impl fmt::Display for DexName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}