use super::ParseError;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Input {
Record,
Body,
Field(String),
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Failure {
Malformed {
offset: usize,
reason: &'static str,
},
Limit {
what: &'static str,
},
Other,
}
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Event {
Parsed,
FallbackParsed,
Error(Failure),
Unparsed,
Rejected,
NoBody,
NoField,
Truncated,
DepthLimit,
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Step {
pub hop: usize,
pub parent: Option<usize>,
pub input: Input,
pub parser: Option<String>,
pub event: Event,
pub kept: bool,
}
#[derive(Debug, Clone, Default)]
pub struct Trace {
pub(super) steps: Vec<Step>,
}
impl Trace {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn steps(&self) -> &[Step] {
&self.steps
}
}
impl Failure {
pub(super) const fn of(error: &ParseError) -> Self {
match error {
ParseError::Malformed { offset, reason } => Self::Malformed {
offset: *offset,
reason,
},
ParseError::Limit { what } => Self::Limit { what },
ParseError::FrameTooLong { .. } => Self::Limit {
what: "framing.max_bytes",
},
ParseError::Other(_) => Self::Other,
}
}
}