Rust Configuration
This page provides a comprehensive reference for all available configuration options, limits, and security controls when initializing a LightVM instance.
Full Configuration Example
The following example demonstrates how to configure all available limits, safety flags, and error options using both the builder and object patterns.
rs
use lightvm::LightVM;
use lightvm::types::{vmconfig::VmConfig, capability::Capability, time_budget::TimeBudget};
fn main() {
let mut vm = LightVM::new(VmConfig {
caps: vec![Capability::Control, Capability::Observe],
..Default::default()
})
.set_max_io(100)
.set_max_import(3)
.set_max_alloc(50)
.set_max_call(200)
.set_max_jump(100)
.set_max_ticks(1_000_000)
.set_max_stack_size(128)
.set_allowed_imports(vec!["math".into(), "time".into(), "utils".into()])
.set_time_budget(TimeBudget::Cheap)
.with_unsafe_mode(false)
.with_nightly(false)
.with_backtrace(false)
.with_explain(false)
.with_hint(true)
.with_diagnostic_links(false);
}rs
use lightvm::LightVM;
use lightvm::types::{
vmconfig::VmConfig,
runtime_config::RuntimeConfig,
error_options::ErrorOptions,
security_config::SecurityConfig,
capability::Capability,
time_budget::TimeBudget
};
fn main() {
let mut vm = LightVM::new(VmConfig {
caps: vec![Capability::Control, Capability::Observe],
runtime_config: Some(RuntimeConfig {
nightly: false
}),
error_options: Some(ErrorOptions {
backtrace: false,
explain: false,
hint: true,
diagnostic_links: false
}),
security_config: Some(SecurityConfig {
max_io: 100,
max_import: 3,
max_alloc: 50,
max_call: 200,
max_jump: 100,
max_ticks: 1_000_000,
max_stack_size: 128,
allowed_imports: vec!["math".into(), "time".into(), "utils".into()],
time_budget: TimeBudget::Cheap,
unsafe_mode: false
})
});
}Configuration Options Breakdown
| Method / Property | Type | Default | Description |
|---|---|---|---|
caps | Vec<Capability> | vec![] (grants Capability::Observe) | Specifies the active capabilities granted to the virtual machine. |
set_max_io / max_io | usize | 100 | Maximum number of I/O operations allowed during execution. |
set_max_import / max_import | usize | 3 | Maximum number of allowed module imports. |
set_max_alloc / max_alloc | usize | 50 | Maximum number of memory allocations allowed. |
set_max_call / max_call | usize | 200 | Maximum number of nested function calls allowed. |
set_max_jump / max_jump | usize | 100 | Maximum number of control flow jumps allowed. |
set_max_ticks / max_ticks | u64 | 1_000_000 | Maximum number of execution ticks before stopping to prevent infinite loops. |
set_max_stack_size / max_stack_size | usize | 128 | Maximum number of items the evaluation stack can hold. |
set_allowed_imports / allowed_imports | Vec<String> | vec!["math".into(), "time".into(), "utils".into()] | Whitelist of module names that are permitted to be imported. |
set_time_budget / time_budget | TimeBudget | TimeBudget::Cheap | Sets the execution time budget tier limit. |
with_unsafe_mode / unsafe_mode | bool | false | Enables or disables system-level unsafe operations. |
with_nightly / nightly | bool | false | Allows the usage of experimental nightly features. |
with_backtrace / backtrace | bool | false | Displays internal backtrace details in error messages. |
with_explain / explain | bool | false | Displays a more detailed explanatory hint in error messages. |
with_hint / hint | bool | true | Displays general usage hints on error messages. |
with_diagnostic_links / diagnostic_links | bool | true | Includes metadata links pointing to error-code documentation. |
Related Documentation
Need to check individual error codes mentioned in error messages? Visit the Error Code Reference.