Skip to main content

Crate uni_plugin_rhai

Crate uni_plugin_rhai 

Source
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 Dynamic and Arrow / DataFusion scalar types.
engine
Per-plugin rhai::Engine factory.
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 + AST adapters hold by reference.
wire_translate
Translate wire-level type strings into internal Arrow DataTypes and uni_plugin signature types.

Structs§

AggregateEntry
One aggregate fn entry.
LoadOutcome
Outcome of a successful Rhai plugin load.
ProcedureEntry
One procedure entry.
RhaiAccumulator
Per-group accumulator backed by a rhai::Dynamic state value.
RhaiAggregateFn
Aggregate fn adapter — implements AggregatePluginFn by dispatching to four Rhai callables.
RhaiHostFnRegistry
Registry of host functions available to Rhai plugins.
RhaiHostFnSpec
Metadata + registrar describing a single host function exposed to Rhai plugins.
RhaiLoader
Rhai loader.
RhaiManifest
Result of parsing a uni_manifest() return value.
RhaiPluginRuntime
Per-plugin runtime state shared across every adapter the plugin registers.
RhaiProcedure
Per-procedure Rhai callable adapter.
RhaiScalarFn
Per-row Rhai scalar function adapter.
ScalarEntry
One scalar fn entry from the Rhai manifest.

Enums§

RhaiError
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.