shindan_maker/
shindan_domain.rs1use anyhow::anyhow;
2use std::fmt;
3use std::str::FromStr;
4
5#[derive(Debug, Clone, Copy)]
7pub enum ShindanDomain {
8 Jp,
9 En,
10 Cn,
11 Kr,
12 Th,
13}
14
15impl fmt::Display for ShindanDomain {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 let url = match self {
18 Self::Jp => "https://shindanmaker.com/",
19 Self::En => "https://en.shindanmaker.com/",
20 Self::Cn => "https://cn.shindanmaker.com/",
21 Self::Kr => "https://kr.shindanmaker.com/",
22 Self::Th => "https://th.shindanmaker.com/",
23 };
24 write!(f, "{}", url)
25 }
26}
27
28impl FromStr for ShindanDomain {
29 type Err = anyhow::Error;
30
31 fn from_str(s: &str) -> anyhow::Result<Self, Self::Err> {
32 match s.to_uppercase().as_str() {
33 "JP" => Ok(Self::Jp),
34 "EN" => Ok(Self::En),
35 "CN" => Ok(Self::Cn),
36 "KR" => Ok(Self::Kr),
37 "TH" => Ok(Self::Th),
38 _ => Err(anyhow!("Invalid domain")),
39 }
40 }
41}
42
43impl TryFrom<&str> for ShindanDomain {
44 type Error = anyhow::Error;
45
46 fn try_from(value: &str) -> anyhow::Result<Self, Self::Error> {
47 value.parse()
48 }
49}
50
51impl TryFrom<String> for ShindanDomain {
52 type Error = anyhow::Error;
53
54 fn try_from(value: String) -> anyhow::Result<Self, Self::Error> {
55 value.parse()
56 }
57}