use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum ParseError {
#[error("未找到匹配的国家代码: {text}")]
NotFound {
text: String,
},
#[error("匹配到多个可能的国家代码: {text}, 候选: {candidates:?}")]
Ambiguous {
text: String,
candidates: Vec<String>,
},
#[error("输入文本格式无效: {text}")]
InvalidInput {
text: String,
},
#[error("配置错误: {message}")]
ConfigError {
message: String,
},
}
impl ParseError {
pub fn not_found(text: &str) -> Self {
ParseError::NotFound {
text: text.to_string(),
}
}
pub fn ambiguous(text: &str, candidates: Vec<String>) -> Self {
ParseError::Ambiguous {
text: text.to_string(),
candidates,
}
}
pub fn invalid_input(text: &str) -> Self {
ParseError::InvalidInput {
text: text.to_string(),
}
}
pub fn config_error(message: &str) -> Self {
ParseError::ConfigError {
message: message.to_string(),
}
}
}