1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use std::{fmt::Display, str::FromStr};

use serde::{Deserialize, Serialize};

use crate::{error::JPreprocessErrorKind, JPreprocessError};

#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
/// 上二
pub enum UpperTwo {
    /// ダ行
    Da,
    /// ハ行
    Ha,
}

impl FromStr for UpperTwo {
    type Err = JPreprocessError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "ダ行" => Ok(Self::Da),
            "ハ行" => Ok(Self::Ha),
            _ => Err(JPreprocessErrorKind::CTypeParseError
                .with_error(anyhow::anyhow!("Parse failed in UpperTwo"))),
        }
    }
}

impl Display for UpperTwo {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match &self {
            Self::Da => "ダ行",
            Self::Ha => "ハ行",
        })
    }
}