ipfix_parser/parsers/
error.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum ParseError {
8 Truncated {
10 context: &'static str,
12 needed: usize,
14 available: usize,
16 },
17 InvalidVersion(u16),
19 InvalidData(String),
21 TemplateLimitExceeded(usize),
24}
25
26impl fmt::Display for ParseError {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match self {
29 ParseError::Truncated {
30 context,
31 needed,
32 available,
33 } => write!(
34 f,
35 "Truncated {}: needed {} octets, {} available",
36 context, needed, available
37 ),
38 ParseError::InvalidVersion(v) => {
39 write!(f, "Invalid version: {} (expected 10)", v)
40 }
41 ParseError::InvalidData(msg) => write!(f, "Invalid data: {}", msg),
42 ParseError::TemplateLimitExceeded(limit) => {
43 write!(f, "Template limit exceeded: {} templates", limit)
44 }
45 }
46 }
47}
48
49impl std::error::Error for ParseError {}
50
51pub type Result<T> = std::result::Result<T, ParseError>;