Skip to main content

set_call_limit

Function set_call_limit 

Source
pub fn set_call_limit(limit: Option<NonZeroUsize>)
Expand description

Sets the maximum cumulative number of counted parser-state calls.

Invocations of ParserState::rule, ParserState::sequence, ParserState::repeat, ParserState::optional, ParserState::lookahead, ParserState::atomic, and ParserState::stack_push consume this budget. Calls are not refunded after returning or backtracking. Repetition counts its entry, not each iteration of its closure. Primitive matches and ParserState::restore_on_err do not consume this cumulative budget. A refused entry fails the parse with “call limit reached”, even if an alternative or optional expression would otherwise recover.

This process-wide setting is captured when each ParserState is created. None disables the cumulative budget. Available native stack space is checked automatically in std builds on the default native targets. Other targets require the stack-guard feature (which enables std). These checks are independent of this setting; insufficient space fails parsing with “stack limit reached”. Stack checking is best-effort when native stack bounds cannot be determined and is not available in no_std builds. It cannot protect arbitrary user callbacks or work outside the parser’s guarded entry points. It is not an elapsed-time or memory limit: individual operations and user closures may perform work without additional counted calls. See the resource-limit guidance for enforcing deadlines.