Skip to content

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 / PropertyTypeDefaultDescription
capsVec<Capability>vec![] (grants Capability::Observe)Specifies the active capabilities granted to the virtual machine.
set_max_io / max_iousize100Maximum number of I/O operations allowed during execution.
set_max_import / max_importusize3Maximum number of allowed module imports.
set_max_alloc / max_allocusize50Maximum number of memory allocations allowed.
set_max_call / max_callusize200Maximum number of nested function calls allowed.
set_max_jump / max_jumpusize100Maximum number of control flow jumps allowed.
set_max_ticks / max_ticksu641_000_000Maximum number of execution ticks before stopping to prevent infinite loops.
set_max_stack_size / max_stack_sizeusize128Maximum number of items the evaluation stack can hold.
set_allowed_imports / allowed_importsVec<String>vec!["math".into(), "time".into(), "utils".into()]Whitelist of module names that are permitted to be imported.
set_time_budget / time_budgetTimeBudgetTimeBudget::CheapSets the execution time budget tier limit.
with_unsafe_mode / unsafe_modeboolfalseEnables or disables system-level unsafe operations.
with_nightly / nightlyboolfalseAllows the usage of experimental nightly features.
with_backtrace / backtraceboolfalseDisplays internal backtrace details in error messages.
with_explain / explainboolfalseDisplays a more detailed explanatory hint in error messages.
with_hint / hintbooltrueDisplays general usage hints on error messages.
with_diagnostic_links / diagnostic_linksbooltrueIncludes metadata links pointing to error-code documentation.

Related Documentation

Need to check individual error codes mentioned in error messages? Visit the Error Code Reference.