pub struct RustiaBuilder { /* private fields */ }Expand description
Chooses a script environment, resource limits, and host services.
Start with Rustia::builder for reproducible defaults, or use
live for real clocks, entropy, and loadstring.
deterministic rejects nondeterministic input providers
and host capabilities. None of these presets sets a fuel or memory limit.
use rustia::Rustia;
let mut lua = Rustia::builder()
.fuel(100_000)
.memory_limit_bytes(4 * 1024 * 1024)
.build()?;
assert_eq!(lua.load("return 6 * 7").eval::<i64>()?, 42);Use build_for_host when callbacks need borrowed
per-invocation state. The more restricted
deterministic_leaf preset is for stateless
decisions and requires a typed host plus an explicit memory limit.
Implementations§
Source§impl RustiaBuilder
impl RustiaBuilder
Sourcepub const fn execution_profile(&self) -> RustiaExecutionProfile
pub const fn execution_profile(&self) -> RustiaExecutionProfile
Returns the typed core execution semantics currently selected by this builder.
Sourcepub fn settings(&self) -> Settings
pub fn settings(&self) -> Settings
Returns the effective limits and service declarations selected so far.
Use Settings::identity_bytes when configuration is part of a replay
or package identity. Provider data and application code remain separate
identity inputs.
Sourcepub fn standard() -> Self
pub fn standard() -> Self
Starts with reproducible inputs and the standard script environment.
This uses Profile::ReproducibleStandard: clocks use deterministic
defaults, the random seed is zero, and loadstring is disabled. Script
print writes to stdout on native/WASI targets and is silent on browser
Wasm until a sink is supplied. Real clocks and other nondeterministic
providers remain available when explicitly configured.
Rustia::builder starts with this preset.
Sourcepub fn deterministic() -> Self
pub fn deterministic() -> Self
Starts with Profile::DeterministicSim and no host services.
Nondeterministic input providers and host capabilities are rejected.
Replay-stable providers and a print sink can still be added explicitly.
Sourcepub fn deterministic_leaf() -> Self
pub fn deterministic_leaf() -> Self
Starts a restricted environment for independent, stateless decisions.
Uses GuestSurface::HardenedLeaf with Profile::DeterministicSim.
Set an explicit memory_limit_bytes and use
build_for_host. Execute host-owned decision
bodies with Rustia::compile_entry and Rustia::invoke_entry_into.
Sourcepub fn live() -> Self
pub fn live() -> Self
Starts with real clocks, a fresh random seed, output, and loadstring.
Uses Profile::ReproducibleStandard with nondeterministic services;
results are not guaranteed to repeat. loadstring lets scripts compile
additional code at runtime, so choose this preset deliberately for
untrusted scripts.
Native and WASI targets use their system services. With the default web-live feature,
wasm32-unknown-unknown uses the JavaScript host (console, Date, performance, and
crypto). Bare-Wasm builds can disable default features and plug the three input
providers explicitly; build then verifies that none are missing.
Sourcepub fn puc51_compat() -> Self
pub fn puc51_compat() -> Self
Starts a Lua 5.1 compatibility environment with loadstring enabled.
The profile alone reproduces PUC 5.1.5 table layout, number
formatting, and table.sort; this preset adds loadstring so PUC-era
code that compiles chunks at runtime works out of the box. Runtime
compilation is an extra capability for untrusted scripts; enable it
where Lua 5.1 source compatibility requires it. Host services otherwise
use the defaults from standard.
Sourcepub fn profile(self, profile: Profile) -> Self
pub fn profile(self, profile: Profile) -> Self
Selects the core compatibility and capability policy. Existing settings and services are retained and checked when building.
Sourcepub fn diagnostic_limits(self, limits: DiagnosticLimits) -> Self
pub fn diagnostic_limits(self, limits: DiagnosticLimits) -> Self
Configures host-side reports independently of guest heap and fuel limits.
Sourcepub fn fuel(self, fuel: u64) -> Self
pub fn fuel(self, fuel: u64) -> Self
Limits the instruction work allowed during execution.
Direct Rustia<()> entry points use this as their top-level budget. A
typed invocation uses the lower of this ceiling and its explicit
crate::InvocationLimits fuel, across every guest call in that
invocation. Fuel measures deterministic work rather than elapsed time;
script pcall cannot catch fuel exhaustion. The default is unlimited.
Sourcepub fn recursion_limit(self, limit: usize) -> Self
pub fn recursion_limit(self, limit: usize) -> Self
Limits nested script calls. The default and maximum are 512.
Larger values are clamped to the engine maximum. Exhaustion returns a
distinct error that script pcall cannot catch.
Sourcepub fn memory_limit_bytes(self, bytes: usize) -> Self
pub fn memory_limit_bytes(self, bytes: usize) -> Self
Limits the VM’s accounted live memory. The default is unlimited.
Accounting is deterministic across native and Wasm targets. It does not bound total process memory, allocator capacity, or memory captured by Rust callbacks. Allocations can fail once the limit is reached.
Sourcepub fn memory_tracking(self, enabled: bool) -> Self
pub fn memory_tracking(self, enabled: bool) -> Self
Enables tracking of live and reserved memory peaks at instruction boundaries.
Sourcepub fn extension(self, extension: RustiaExtension) -> Self
pub fn extension(self, extension: RustiaExtension) -> Self
Adds a group of Rust callbacks to install when the VM is built.
For a typed host, use crate::HostModule after building instead.
Sourcepub fn stdout(self, sink: impl FnMut(&str) + 'static) -> Self
pub fn stdout(self, sink: impl FnMut(&str) + 'static) -> Self
Chooses where script print output goes.
Each call sends one string, with arguments joined by tabs and a trailing
newline. The closure cannot return an error. Output sinks are allowed in
every ordinary profile, including Profile::DeterministicSim.
Sourcepub fn without_stdout(self) -> Self
pub fn without_stdout(self) -> Self
Discards script print output by removing the configured sink.
Sourcepub fn module_resolver(self, resolver: ServiceModuleResolver) -> Self
pub fn module_resolver(self, resolver: ServiceModuleResolver) -> Self
Installs the host-owned resolver behind script-visible require.
The resolver chooses a canonical module identity and source for every
request. Successful results are cached by identity within the calling
function’s module cohort: the cache shared by a module and its dependencies.
Each installation starts a fresh cohort; retained functions keep using
their original cohort. A module can therefore execute again in a new
installation before Rustia::reset_decision clears all guest state.
See ServiceModuleResolver for loading, failure, and suspension rules.
Sourcepub fn wall_clock(self, clock: ServiceClock) -> Self
pub fn wall_clock(self, clock: ServiceClock) -> Self
Supplies the clock for no-argument os.time() and the default os.date
timestamp. A nondeterministic provider is rejected at build on
DeterministicSim.
Sourcepub fn monotonic_clock(self, clock: ServiceClock) -> Self
pub fn monotonic_clock(self, clock: ServiceClock) -> Self
Supplies the clock for os.clock(), overriding the VM’s built-in
logical clock. Same DeterministicSim validation as wall_clock.
Sourcepub fn entropy(self, entropy: ServiceEntropy) -> Self
pub fn entropy(self, entropy: ServiceEntropy) -> Self
Supplies the seed read once at VM construction for the initial math.random
sequence. Calling math.randomseed later still replaces that state. A nondeterministic
provider is rejected by deterministic.
Sourcepub fn build(self) -> Result<Rustia>
pub fn build(self) -> Result<Rustia>
Validates the configuration and builds a VM without a typed host context.
Returns an error for incompatible services, invalid extensions, or a
hardened-leaf preset, which requires build_for_host.
Sourcepub fn build_for_host<H>(self) -> Result<Rustia<H>>where
H: HostSchema,
pub fn build_for_host<H>(self) -> Result<Rustia<H>>where
H: HostSchema,
Builds a typed VM while preserving this builder’s profile, settings, and host services.
Legacy RustiaExtension values deliberately do not cross into the
typed capability surface; install a crate::HostModule<H> after
building instead.