use std::fmt;
pub const DEFAULT_MAX_DEPTH: u32 = 256;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum LimitExceeded {
Depth {
max: u32,
line: u32,
column: u32,
},
Nesting {
max: u32,
},
Stack {
max: u32,
},
}
impl LimitExceeded {
#[must_use]
pub const fn max(self) -> u32 {
match self {
Self::Depth { max, .. } | Self::Nesting { max } | Self::Stack { max } => max,
}
}
}
impl fmt::Display for LimitExceeded {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Depth { max, line, column } => write!(
f,
"{line}:{column}: element nested deeper than the maximum depth of {max}"
),
Self::Nesting { max } => write!(
f,
"templates and functions invoked one inside another more than {max} deep"
),
Self::Stack { max } => write!(
f,
"templates and functions invoked one inside another use more than {max} bytes of stack"
),
}
}
}