Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The public embedding API for the Ion interpreter.

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Source

pub fn with_output<H>(output: H) -> Self
where H: OutputHandler + 'static,

Create an engine with a host-provided output handler for io::print*.

Source

pub fn with_output_handler(output: Arc<dyn OutputHandler>) -> Self

Create an engine with a shared host-provided output handler.

Source

pub fn eval(&mut self, source: &str) -> Result<Value, IonError>

Evaluate a script, returning the last expression’s value.

Source

pub fn set(&mut self, name: &str, value: Value)

Inject a value into the script scope.

Source

pub fn get(&self, name: &str) -> Option<Value>

Read a variable from the script scope.

Source

pub fn get_all(&self) -> HashMap<String, Value>

Get all top-level bindings.

Source

pub fn set_limits(&mut self, limits: Limits)

Set execution limits.

Source

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.

Source

pub fn set_output_handler(&mut self, output: Arc<dyn OutputHandler>)

Set a shared host output handler used by io::print*.

Source

pub fn register_fn( &mut self, name: &str, func: fn(&[Value]) -> Result<Value, String>, )

Register a built-in function.

Source

pub fn register_closure<F>(&mut self, name: &str, func: F)
where F: Fn(&[Value]) -> Result<Value, String> + Send + Sync + 'static,

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.

Source

pub fn register_struct(&mut self, def: HostStructDef)

Register a host struct type that scripts can construct and match on.

Source

pub fn register_enum(&mut self, def: HostEnumDef)

Register a host enum type that scripts can construct and match on.

Source

pub fn register_module(&mut self, module: Module)

Register a module that scripts can access via module::name or use module::*.

Source

pub fn register_type<T: IonType>(&mut self)

Register a type via the IonType trait (used with #[derive(IonType)]).

Source

pub fn set_typed<T: IonType>(&mut self, name: &str, value: &T)

Inject a typed Rust value into the script scope.

Source

pub fn get_typed<T: IonType>(&self, name: &str) -> Result<T, String>

Extract a typed Rust value from the script scope.

Source

pub fn vm_eval(&mut self, source: &str) -> Result<Value, IonError>

Evaluate a script via the bytecode VM. Falls back to tree-walk for unsupported features (concurrency).

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.