use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParseError {
Truncated {
context: &'static str,
needed: usize,
available: usize,
},
InvalidVersion(u16),
InvalidData(String),
TemplateLimitExceeded(usize),
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ParseError::Truncated {
context,
needed,
available,
} => write!(
f,
"Truncated {}: needed {} octets, {} available",
context, needed, available
),
ParseError::InvalidVersion(v) => {
write!(f, "Invalid version: {} (expected 10)", v)
}
ParseError::InvalidData(msg) => write!(f, "Invalid data: {}", msg),
ParseError::TemplateLimitExceeded(limit) => {
write!(f, "Template limit exceeded: {} templates", limit)
}
}
}
}
impl std::error::Error for ParseError {}
pub type Result<T> = std::result::Result<T, ParseError>;