#[non_exhaustive]pub enum ScratchRequirement {
None,
Fixed {
bytes: usize,
},
PerElement {
bytes_per_element: usize,
},
Unbounded,
}Expand description
Scratch memory an operation needs beyond its inputs and outputs.
Declared up front so a caller can budget, pre-reserve, or refuse before any
work starts. Unbounded is deliberately representable and deliberately
unpleasant: an operation that cannot bound its scratch must say so rather
than allocating silently in a hot loop.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
None
Operates in place; no scratch beyond inputs and outputs.
Fixed
At most bytes of scratch, independent of input size.
PerElement
At most bytes_per_element * elements of scratch.
Unbounded
Scratch cannot be bounded ahead of time.
Callers must treat this as “may allocate arbitrarily”; a memory budget cannot be enforced against it.
Implementations§
Source§impl ScratchRequirement
impl ScratchRequirement
Sourcepub const fn upper_bound_bytes(self, elements: usize) -> Option<usize>
pub const fn upper_bound_bytes(self, elements: usize) -> Option<usize>
Upper bound for elements inputs, or None when unbounded.
Sourcepub fn fits_budget(self, options: &ExecutionOptions, elements: usize) -> bool
pub fn fits_budget(self, options: &ExecutionOptions, elements: usize) -> bool
Whether this requirement fits options’ memory budget for elements.
An unbounded requirement never fits a declared budget: allowing it would make the budget advisory, which is the failure this type exists to stop. Whether this requirement fits the caller’s memory budget.
No longer const: it reads an ExecutionOptions that now owns a
shared cancellation handle, so it cannot be destructured at compile
time. Budget checks happen once per dispatch, not on a hot path.