pub struct Engine { /* private fields */ }Expand description
The public embedding API for the Ion interpreter.
Implementations§
Source§impl Engine
impl Engine
pub fn new() -> Self
Sourcepub fn with_output<H>(output: H) -> Selfwhere
H: OutputHandler + 'static,
pub fn with_output<H>(output: H) -> Selfwhere
H: OutputHandler + 'static,
Create an engine with a host-provided output handler for io::print*.
Sourcepub fn with_output_handler(output: Arc<dyn OutputHandler>) -> Self
pub fn with_output_handler(output: Arc<dyn OutputHandler>) -> Self
Create an engine with a shared host-provided output handler.
Sourcepub fn eval(&mut self, source: &str) -> Result<Value, IonError>
pub fn eval(&mut self, source: &str) -> Result<Value, IonError>
Evaluate a script, returning the last expression’s value.
Sourcepub fn set_limits(&mut self, limits: Limits)
pub fn set_limits(&mut self, limits: Limits)
Set execution limits.
Sourcepub fn set_output<H>(&mut self, output: H)where
H: OutputHandler + 'static,
pub fn set_output<H>(&mut self, output: H)where
H: OutputHandler + 'static,
Set the host output handler used by io::print, io::println, and
io::eprintln.
Sourcepub fn set_output_handler(&mut self, output: Arc<dyn OutputHandler>)
pub fn set_output_handler(&mut self, output: Arc<dyn OutputHandler>)
Set a shared host output handler used by io::print*.
Sourcepub fn register_fn(
&mut self,
name: &str,
func: fn(&[Value]) -> Result<Value, String>,
)
pub fn register_fn( &mut self, name: &str, func: fn(&[Value]) -> Result<Value, String>, )
Register a built-in function.
Sourcepub fn register_closure<F>(&mut self, name: &str, func: F)
pub fn register_closure<F>(&mut self, name: &str, func: F)
Register a built-in backed by a closure. Unlike register_fn,
this accepts any Fn — including closures that capture
host-side state such as a tokio::runtime::Handle, a database
pool, or shared counters. See docs/concurrency.md for the
tokio embedding pattern.
Sourcepub fn register_struct(&mut self, def: HostStructDef)
pub fn register_struct(&mut self, def: HostStructDef)
Register a host struct type that scripts can construct and match on.
Sourcepub fn register_enum(&mut self, def: HostEnumDef)
pub fn register_enum(&mut self, def: HostEnumDef)
Register a host enum type that scripts can construct and match on.
Sourcepub fn register_module(&mut self, module: Module)
pub fn register_module(&mut self, module: Module)
Register a module that scripts can access via module::name or use module::*.
Sourcepub fn register_type<T: IonType>(&mut self)
pub fn register_type<T: IonType>(&mut self)
Register a type via the IonType trait (used with #[derive(IonType)]).
Sourcepub fn set_typed<T: IonType>(&mut self, name: &str, value: &T)
pub fn set_typed<T: IonType>(&mut self, name: &str, value: &T)
Inject a typed Rust value into the script scope.