shindan_maker/
domain.rs

1use anyhow::Result;
2use std::fmt;
3use std::str::FromStr;
4
5/// A domain of ShindanMaker.
6#[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) -> 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::anyhow!("Invalid domain")),
39        }
40    }
41}