#[non_exhaustive]pub enum Limit {
Expansions {
max: usize,
},
Tokens {
max: usize,
},
}Expand description
Which part of a Budget an expansion ran out of, reported by
ExpandError::Budget.
Depth is not listed: exceeding Budget::max_depth keeps reporting
ExpandError::RecursionLimit, as it
did before budgets existed. The enum is #[non_exhaustive] so that further
limits can be added in a minor release.
§Examples
use macro_lang::{Budget, Context, ExpandError, Expander, Limit, Macro, Rule, Template};
use intern_lang::Interner;
use token_lang::Span;
let mut names = Interner::new();
// three!() => a b c
let three = Macro::new(names.intern("three"), vec![Rule {
pattern: vec![],
template: "abc".chars().map(|c| Template::token(c, Span::new(0, 1))).collect(),
}])?;
let mut expander = Expander::with_budget(Budget::DEFAULT.with_max_tokens(5));
assert!(expander.expand(&three, &[], Span::new(0, 1), Context::ROOT).is_ok());
// Three more tokens would make six, one more than the budget allows.
assert_eq!(
expander.expand(&three, &[], Span::new(0, 1), Context::ROOT),
Err(ExpandError::Budget(Limit::Tokens { max: 5 })),
);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Expansions
Budget::max_expansions expansions have already been performed.
Tokens
The expansion would write more than Budget::max_tokens tokens in
total.
Trait Implementations§
impl Copy for Limit
impl Eq for Limit
impl StructuralPartialEq for Limit
Auto Trait Implementations§
impl Forget for Limit
impl Freeze for Limit
impl Move for Limit
impl RefUnwindSafe for Limit
impl Send for Limit
impl Sync for Limit
impl Unpin for Limit
impl UnsafeUnpin for Limit
impl UnwindSafe for Limit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more