df_hyperliquid_core/deploy/
name.rs1use std::{fmt, str::FromStr};
4
5use crate::deploy::error::BadDeploy;
6
7#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
12pub struct DexName(String);
13
14impl DexName {
15 #[must_use]
17 pub fn as_str(&self) -> &str {
18 &self.0
19 }
20}
21
22impl FromStr for DexName {
23 type Err = BadDeploy;
24
25 fn from_str(name: &str) -> Result<Self, Self::Err> {
27 let letters = name.bytes().all(|byte| byte.is_ascii_lowercase());
28 if !(2..=4).contains(&name.len()) || !letters {
29 return Err(BadDeploy::Name(name.to_owned()));
30 }
31 Ok(DexName(name.to_owned()))
32 }
33}
34
35impl fmt::Display for DexName {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 f.write_str(&self.0)
38 }
39}