chinese_number/chinese_to_number/
chinese_to_number_error.rs1use core::fmt::{self, Display, Formatter};
2#[cfg(feature = "std")]
3use std::error::Error;
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq)]
7pub enum ChineseToNumberError {
8 ChineseNumberEmpty,
9 ChineseNumberIncorrect { char_index: usize },
10 Overflow,
11 Underflow,
12}
13
14impl Display for ChineseToNumberError {
15 #[inline]
16 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
17 match self {
18 ChineseToNumberError::ChineseNumberEmpty => {
19 f.write_str("a chinese number cannot be empty")
20 },
21 ChineseToNumberError::ChineseNumberIncorrect {
22 char_index,
23 } => f.write_fmt(format_args!(
24 "the chinese number is incorrect (position: {})",
25 char_index
26 )),
27 ChineseToNumberError::Overflow => f.write_str("number is too large"),
28 ChineseToNumberError::Underflow => f.write_str("number is too small"),
29 }
30 }
31}
32
33#[cfg(feature = "std")]
34impl Error for ChineseToNumberError {}