pub struct ResourceLimits {
pub max_duration: Option<Duration>,
pub max_memory: Option<usize>,
pub gc_interval: Option<usize>,
pub max_recursion_depth: usize,
}Expand description
Configuration for resource limits.
The time/memory/GC limits are optional — set to None to disable — but
recursion depth is always bounded (default
DEFAULT_MAX_RECURSION_DEPTH): unbounded recursion would let sandboxed
code overflow the native stack and abort the process. Use
ResourceLimits::default() for the recursion-only defaults, or build
custom limits with the builder pattern.
Fields§
§max_duration: Option<Duration>Maximum execution time.
max_memory: Option<usize>Maximum allocator-backed memory in bytes.
Requires the executable to install and arm monty-alloc.
gc_interval: Option<usize>Run garbage collection every N GC-tracked allocations.
max_recursion_depth: usizeMaximum recursion depth (function call stack depth).
Implementations§
Source§impl ResourceLimits
impl ResourceLimits
Sourcepub fn max_duration(self, limit: Duration) -> Self
pub fn max_duration(self, limit: Duration) -> Self
Sets the maximum execution duration.
Sourcepub fn max_memory(self, limit: usize) -> Self
pub fn max_memory(self, limit: usize) -> Self
Sets allocator-backed maximum memory usage in bytes.
Requires the executable to install and arm monty-alloc; otherwise
the limit is silently not enforced.
Sourcepub fn gc_interval(self, interval: usize) -> Self
pub fn gc_interval(self, interval: usize) -> Self
Sets the garbage collection interval (run GC every N GC-tracked allocations).
Sourcepub fn max_recursion_depth(self, limit: usize) -> Self
pub fn max_recursion_depth(self, limit: usize) -> Self
Sets the maximum recursion depth (function call stack depth).
Trait Implementations§
Source§impl Clone for ResourceLimits
impl Clone for ResourceLimits
Source§fn clone(&self) -> ResourceLimits
fn clone(&self) -> ResourceLimits
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ResourceLimits
impl Debug for ResourceLimits
Source§impl Default for ResourceLimits
Creates a new ResourceLimits with all limits disabled, except max recursion which is set to 1000.
impl Default for ResourceLimits
Creates a new ResourceLimits with all limits disabled, except max recursion which is set to 1000.