pub struct Budget { /* private fields */ }Expand description
Explicit limits on the work untrusted input can cause.
The resolver is linear in the size of the program except in three places,
each bounded here: glob imports (each glob edge carries every name of its
target), inheritance walks for member lookups, and did-you-mean
comparisons. Exceeding the first two fails the run with
ResolveError::BudgetExceeded; exhausting the suggestion budget only
stops suggestions.
§Examples
use resolve_lang::Budget;
let b = Budget::default().with_glob_bindings(1_000);
assert_eq!(b.glob_bindings(), 1_000);
assert!(Budget::unlimited().suggestion_cells() > b.suggestion_cells());Implementations§
Source§impl Budget
impl Budget
Sourcepub const fn unlimited() -> Self
pub const fn unlimited() -> Self
No limits (for trusted input).
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::unlimited().member_steps(), u64::MAX);Sourcepub const fn with_glob_bindings(self, n: u64) -> Self
pub const fn with_glob_bindings(self, n: u64) -> Self
Sets the glob-binding limit.
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::default().with_glob_bindings(5).glob_bindings(), 5);Sourcepub const fn with_member_steps(self, n: u64) -> Self
pub const fn with_member_steps(self, n: u64) -> Self
Sets the member-lookup step limit.
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::default().with_member_steps(5).member_steps(), 5);Sourcepub const fn with_suggestion_cells(self, n: u64) -> Self
pub const fn with_suggestion_cells(self, n: u64) -> Self
Sets the did-you-mean budget, in edit-distance table cells.
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::default().with_suggestion_cells(0).suggestion_cells(), 0);Sourcepub const fn glob_bindings(&self) -> u64
pub const fn glob_bindings(&self) -> u64
The glob-binding limit.
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::default().glob_bindings(), 16_000_000);Sourcepub const fn member_steps(&self) -> u64
pub const fn member_steps(&self) -> u64
The member-lookup step limit.
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::default().member_steps(), 16_000_000);Sourcepub const fn suggestion_cells(&self) -> u64
pub const fn suggestion_cells(&self) -> u64
The did-you-mean budget.
§Examples
use resolve_lang::Budget;
assert_eq!(Budget::default().suggestion_cells(), 32_000_000);Trait Implementations§
impl Copy for Budget
impl Eq for Budget
impl StructuralPartialEq for Budget
Auto Trait Implementations§
impl Freeze for Budget
impl RefUnwindSafe for Budget
impl Send for Budget
impl Sync for Budget
impl Unpin for Budget
impl UnsafeUnpin for Budget
impl UnwindSafe for Budget
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