Expand description
Embedder-facing API for Rex.
Rex is a strict, statically typed, pure functional language intended to be
embedded in Rust applications. Host programs provide modules and native
functions, then run user-supplied Rex snippets or module files to coordinate
work. The main public API is the engine module, especially
Engine for configuring the runtime and
Module for exposing host capabilities to Rex code.
Most embedders start with
Engine::with_prelude, register one or more
host modules, then evaluate a snippet or module through an
Evaluator. The parser, type system, runtime value, and
JSON conversion APIs are also re-exported here so an application can choose
how much of the Rex pipeline it wants to control.
§Minimal embedding example
use rex::engine::{Engine, EngineError, Module};
let mut engine = Engine::with_prelude(())?;
engine.add_default_resolvers();
let mut math = Module::new("host.math");
math.export("inc", |_state: &(), x: i32| {
Ok::<i32, EngineError>(x + 1)
})?;
engine.inject_module(math)?;
let (value, typ) = engine
.into_evaluator()
.eval_snippet("import host.math (inc);\ninc 41")
.await?;
assert_eq!(typ.to_string(), "i32");
assert_eq!(value.as_i32()?, 42);For lightweight tests and command-line style integrations, eval parses,
typechecks, evaluates, and converts the result to JSON in one call. Production
embedders usually use Engine directly so they can
register host modules, set execution bounds, inspect type information, and
handle compile and evaluation errors separately.
Modules§
- ast
- Rex abstract syntax tree types produced by the parser. Source-level syntax tree types.
- engine
- Compile-time and runtime APIs for embedding Rex in a Rust host program. Compile and run Rex programs from a Rust host.
- json
- Conversion between JSON values and typed Rex runtime values. JSON conversion helpers for runtime Rex values.
- parser
- Source parser entry points and parse diagnostics. Parse Rex source text into AST values.
- typesystem
- Hindley-Milner type inference, type representations, ADTs, and type classes. Type inference and Rex type metadata.
Functions§
- eval
- Parse, typecheck, evaluate, and JSON-encode a Rex snippet.
Derive Macros§
- Rex
- Derive bridge for Rust data types that should cross the Rex boundary.