From 57181752917c67a007c86fdbe133d2c64db7c749 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 28 Sep 2023 15:20:04 +0200 Subject: Move Level into the crate root --- askama_parser/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'askama_parser/src/lib.rs') diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs index 1e48262..de88a20 100644 --- a/askama_parser/src/lib.rs +++ b/askama_parser/src/lib.rs @@ -324,3 +324,18 @@ impl Default for Syntax<'static> { } } } + +#[derive(Clone, Copy, Default)] +pub(crate) struct Level(u8); + +impl Level { + fn nest(self, i: &str) -> Result>> { + if self.0 >= Self::MAX_DEPTH { + return Err(nom::Err::Failure(error_position!(i, ErrorKind::TooLarge))); + } + + Ok(Level(self.0 + 1)) + } + + const MAX_DEPTH: u8 = 64; +} -- cgit