Expand description
Rhai-script loader for the uni-db plugin framework.
uni-plugin-rhai is the host-embedded scripting loader. It sits
parallel to uni-plugin-extism (Extism bytes-in/bytes-out WASM) and
uni-plugin-wasm (Component Model WIT) but takes a fundamentally
different shape: there is no WASM wrapper, no IPC, no instance pool —
the Rhai rhai::Engine is embedded directly in the host process.
§Why Rhai
Rhai fills the “dynamic AND sandboxed” loader quadrant:
- Pure Rust — no C toolchain, no WASM wrapper, no separate runtime. Builds anywhere uni-db builds.
- Sandboxed by language design — Rhai has no built-in I/O. Every effectful operation comes from a host-registered function. Registering a function is opt-in; absence is the default and matches the framework’s capability-gating contract (proposal §10.2).
- Resource limits are first-class on the
Engine:set_max_operations,set_max_call_levels,set_max_string_size,set_max_array_size,set_max_map_size. No ad-hoc instruction-count shim. - Actively maintained on crates.io 1.x.
§Capability gating — Engine-import absence
The capability-enforcement layer 2 for Rhai is Engine-import absence:
the loader registers a host function (uni.fs.read, uni.http.get,
uni.query, …) on the per-plugin Engine only when the corresponding
capability is in the effective grant set. A plugin without
Capability::Filesystem cannot call uni.fs.read — Rhai raises
ErrorFunctionNotFound at parse-resolution time. This is the in-host
analogue of Component Model’s linker-absence guarantee.
§Crate status
Implemented in phases. Phase 1 (this) ships the crate scaffold;
phases 2+ wire the Engine factory, manifest parser, adapters, and
Uni::load_rhai_plugin.
Modules§
- adapter
- Scalar function adapter — turns a Rhai callable into an
uni_plugin::traits::scalar::ScalarPluginFn. - adapter_
aggregate - Aggregate function adapter — Rhai-side aggregate via four named fns.
- adapter_
procedure - Procedure adapter — Rhai-side procedure returning a stream of yield rows.
- columns
- Vectorized column userdata for Rhai plugins.
- dynamic_
bridge - Bridge between Rhai’s
Dynamicand Arrow / DataFusion scalar types. - engine
- Per-plugin
rhai::Enginefactory. - error
- Error types for the Rhai loader.
- host_
fn_ impls - Capability-gated host fns surfaced to Rhai scripts.
- host_
fns - Host function registration surface for Rhai plugins.
- loader
- Rhai loader — three-phase load mirroring
ExtismLoader::load. - manifest
- Rhai-side manifest reader.
- runtime
- Shared per-plugin runtime — the
Engine+ASTadapters hold by reference. - wire_
translate - Translate wire-level type strings into internal Arrow
DataTypes anduni_pluginsignature types.
Structs§
- Aggregate
Entry - One aggregate fn entry.
- Load
Outcome - Outcome of a successful Rhai plugin load.
- Procedure
Entry - One procedure entry.
- Rhai
Accumulator - Per-group accumulator backed by a
rhai::Dynamicstate value. - Rhai
Aggregate Fn - Aggregate fn adapter — implements
AggregatePluginFnby dispatching to four Rhai callables. - Rhai
Host FnRegistry - Registry of host functions available to Rhai plugins.
- Rhai
Host FnSpec - Metadata + registrar describing a single host function exposed to Rhai plugins.
- Rhai
Loader - Rhai loader.
- Rhai
Manifest - Result of parsing a
uni_manifest()return value. - Rhai
Plugin Runtime - Per-plugin runtime state shared across every adapter the plugin registers.
- Rhai
Procedure - Per-procedure Rhai callable adapter.
- Rhai
Scalar Fn - Per-row Rhai scalar function adapter.
- Scalar
Entry - One scalar fn entry from the Rhai manifest.
Enums§
- Rhai
Error - Errors specific to the Rhai loader.
Constants§
- DEFAULT_
MAX_ CALL_ LEVELS - Default maximum recursion depth for Rhai scripts. Overridable by
scripts via the loader’s per-plugin engine configuration; future:
expose a
Capability::MaxCallLevels(N)so plugins can request more.
Functions§
- build_
engine - Build a Rhai engine pre-configured for a single plugin’s effective capability set.