1use alloc::string::String;
4use core::fmt;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum KhamError {
9 InvalidUtf8,
11 DictLoadError(String),
15 CorruptDict,
17 EmptyInput,
19}
20
21impl fmt::Display for KhamError {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 match self {
24 KhamError::InvalidUtf8 => f.write_str("invalid UTF-8 sequence"),
25 KhamError::DictLoadError(msg) => write!(f, "dictionary load error: {msg}"),
26 KhamError::CorruptDict => {
27 f.write_str("dictionary data is corrupt or has wrong version")
28 }
29 KhamError::EmptyInput => f.write_str("input must not be empty"),
30 }
31 }
32}
33
34#[cfg(feature = "std")]
36extern crate std;
37
38#[cfg(feature = "std")]
40impl std::error::Error for KhamError {}