Nesting

Struct Nesting 

Source
pub struct Nesting { /* private fields */ }
Expand description

A recursion counter, held by whatever is recursing.

The discipline is enter at the recursion site and leave on the way out — at the site, not at one grammar rule that seemed to be where nesting comes from. That is the Scriban lesson (GHSA-p6q4-fgr8-vx4p, §42.2): a limit added at the one production somebody thought of was bypassed through a different one.

Implementations§

Source§

impl Nesting

Source

pub fn new() -> Nesting

Source

pub fn with_limit(limit: u32) -> Nesting

A counter with a lower ceiling, for a test that would rather not build a 256-deep input.

Source

pub fn resumed(&self) -> Nesting

A counter for a sub-parse that continues this one, starting at the depth already reached.

A sub-parser over a captured token run is still inside whatever brackets captured it, and a counter that started again at zero would be a way in — the same shape of bypass the Scriban advisory records.

Source

pub fn limit(&self) -> u32

Source

pub fn depth(&self) -> u32

Source

pub fn enter(&mut self) -> bool

Descend one level. false means the ceiling is reached and the caller must not recurse — and must not leave either, because nothing was entered.

Source

pub fn leave(&mut self)

Source

pub fn should_report(&mut self) -> bool

True exactly once per compilation.

One over-deep expression is refused at every level on the way out, and a reader wants the count, not one copy of it per level.

Source

pub fn note(&self) -> String

The note every site prints, so the three of them say the same thing.

Source

pub fn note_about(&self, what: &str) -> String

The same note, naming the axis being counted.

Two axes reach the same stack — nesting depth and the length of a flat chain (MAX_BLOCK) — and a note that called the second “nesting” would send a reader looking for brackets in a function that has none.

Trait Implementations§

Source§

impl Debug for Nesting

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Nesting

Source§

fn default() -> Nesting

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.