Skip to main content

RuntimeEngine

Struct RuntimeEngine 

Source
pub struct RuntimeEngine { /* private fields */ }

Implementations§

Source§

impl RuntimeEngine

Source

pub fn new() -> Self

Create a runtime with all built-in primitive descriptors.

§Panics

Panics only if a compile-time built-in descriptor violates the same validation rules enforced for downstream custom primitives.

Source

pub fn compile(&mut self, source: &str) -> Result<CompiledUi, RuntimeError>

Compile the default application entry source.

§Errors

Returns RuntimeError::Compile when Rhai rejects the source.

Source

pub fn compile_named( &mut self, source_name: &str, source: &str, ) -> Result<CompiledUi, RuntimeError>

Compile source with an explicit diagnostic name and advance the script generation.

§Errors

Returns RuntimeError::Compile when Rhai rejects the source.

Source

pub fn compile_self_contained_named( &mut self, source_name: &str, source: &str, ) -> Result<CompiledUi, RuntimeError>

Compile source while eagerly resolving and embedding literal imports.

§Errors

Returns RuntimeError::Compile for source, import, or module errors.

Source

pub fn set_module_resolver(&mut self, resolver: impl ModuleResolver + 'static)

Source

pub fn with_program_preparation<T, E>( &mut self, operation: impl FnOnce(&mut Self) -> Result<T, E>, ) -> Result<T, E>

Compile all modules and the entry AST for one candidate under one unique program identity. Independent calls receive different generations even when neither candidate has been rendered yet.

§Errors

Returns the error produced by operation.

Source

pub fn render(&mut self, compiled: &CompiledUi) -> Result<UiNode, RuntimeError>

Evaluate the compiled application’s view function.

§Errors

Returns RuntimeError::Evaluate when view is missing, fails, or returns a value other than UiNode.

Source

pub fn render_with_context( &mut self, compiled: &CompiledUi, context: UiContext, ) -> Result<UiNode, RuntimeError>

Evaluate the compiled application’s view(ctx) function.

§Errors

Returns RuntimeError::Evaluate when view fails or returns a value other than UiNode.

Source

pub fn call_optional_lifecycle( &self, compiled: &CompiledUi, function: &str, context: UiContext, ) -> Result<bool, RuntimeError>

Invoke an optional one-argument lifecycle function.

§Errors

Returns RuntimeError::Evaluate when the function exists but fails.

Source

pub fn root_state_schema( &self, compiled: &CompiledUi, ) -> Result<ComponentStateSchema, RuntimeError>

Decode optional root state_schema() from an application entry.

§Errors

Returns RuntimeError::Evaluate when the function fails or cannot be decoded as ComponentStateSchema.

Source

pub fn callback( &self, compiled: &CompiledUi, function_name: &str, ) -> Result<ScriptCallback, RuntimeError>

Create a generation-bound callback for a script function.

§Errors

Returns RuntimeError::CallbackDefinition when the function name is not a valid Rhai function pointer name.

Source

pub fn invoke_callback( &self, compiled: &CompiledUi, callback: &ScriptCallback, args: impl FuncArgs, ) -> Result<Dynamic, RuntimeError>

Invoke a callback only when it belongs to the current compiled generation.

§Errors

Returns RuntimeError::StaleCallback for obsolete callbacks and RuntimeError::Evaluate when the Rhai function fails.

Source

pub fn is_current(&self, generation: ScriptGeneration) -> bool

Source

pub fn engine(&self) -> &Engine

Source

pub fn definition_source(&self) -> String

Generate the official Rhai language-server definition source for every function/type/module registered on this engine.

Standard packages are omitted because the language server supplies them.

Source

pub fn lint_known_calls( &mut self, entry_name: &str, entry_source: &str, modules: &BTreeMap<ModuleId, String>, ) -> Result<Vec<KnownCallDiagnostic>, KnownCallLintError>

Validate statically visible direct and method call arities in an entry script and its installed modules.

This complements real lifecycle execution because Rhai resolves functions dynamically and an initial render cannot cover every branch. The catalog comes from the same registered Engine metadata used by Self::definition_source.

§Errors

Returns a metadata or parse error if the lint catalog cannot be built.

Source

pub fn component_exports( &self, ) -> Result<ComponentRegistry, ComponentExportError>

Return a snapshot of components exported through this engine.

§Errors

Returns ComponentExportError if the export registry was poisoned by a prior panic.

Source

pub fn component_invocations( &self, ) -> impl ExactSizeIterator<Item = &ComponentInvocationRecipe>

Source

pub fn clear_component_exports(&self) -> Result<(), ComponentExportError>

Clear component exports before evaluating a hot-reload candidate.

§Errors

Returns ComponentExportError if the collector is unavailable.

Source

pub fn restore_component_exports( &self, registry: ComponentRegistry, ) -> Result<(), ComponentExportError>

Restore a prior export snapshot after a rejected candidate.

§Errors

Returns ComponentExportError if the collector is unavailable.

Source

pub fn register_primitive( &mut self, descriptor: PrimitiveDescriptor, handler: impl PrimitiveHandler + 'static, ) -> Result<(), PrimitiveError>

Register a namespaced Rust custom primitive and its Rhai constructor.

§Errors

Returns PrimitiveError when the descriptor conflicts or is invalid.

Source

pub fn primitive_registry(&self) -> PrimitiveRegistry

Source

pub fn register_native_handler( &self, descriptor: NativeHandlerDescriptor, handler: impl FnMut(NativeEvent, &mut UiRuntimeState, &mut Window, &mut App) -> Result<EventResponse, String> + 'static, ) -> Result<(), NativeHandlerError>

Register a trusted Rust handler attachable by Rhai through native_handler.

§Errors

Returns descriptor/duplicate registry errors.

Source

pub fn native_handler_registry(&self) -> NativeHandlerRegistry

Source

pub fn syntax_registry(&self) -> SyntaxRegistry

Source

pub fn document_runtime_config(&self) -> DocumentRuntimeConfig

Source

pub fn set_slow_threshold(&mut self, threshold: Duration)

Source

pub fn set_operation_limit(&mut self, limit: u64)

Set the per-execution script operation budget.

The default is DEFAULT_SCRIPT_OPERATION_LIMIT. This is a cumulative operation quota for each execution round, not a frame-time guarantee. A host that runs known one-shot, cacheable script phases (a layout pass, an analysis sweep) may raise it; the wall-clock slow threshold still flags anything that stalls the foreground. Scripts cannot change this limit; only the embedding application can. Zero normalizes to one; it never disables protection. Changes apply to subsequent calls. Native Rust work is not preempted by this quota.

Source

pub fn operation_limit(&self) -> u64

The per-execution script operation budget in force.

Source

pub fn set_expression_depth_limits(&mut self, global: usize, functions: usize)

Configure parser depth independently of execution/recursion/data limits. Defaults are global=64/function=32 in both debug and release. Zero normalizes to one rather than adopting Rhai’s unlimited convention.

Source

pub fn expression_depth_limits(&self) -> (usize, usize)

Source

pub fn take_timings(&self) -> Vec<ExecutionTiming>

Source

pub fn last_failed_timing(&self) -> Option<ExecutionTiming>

Return the failed timing from the current execution session, if any. Starting the next compile, render, callback, or lifecycle call clears it.

Trait Implementations§

Source§

impl Default for RuntimeEngine

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more