Skip to main content

ScriptEngine

Trait ScriptEngine 

Source
pub trait ScriptEngine: Send + Sync {
    // Required method
    fn eval<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        script: &'life1 ScriptSource,
        entry: &'life2 str,
        input: Value,
        limits: &'life3 ScriptLimits,
    ) -> Pin<Box<dyn Future<Output = Result<Value, ScriptError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;

    // Provided method
    fn eval_blocking(
        &self,
        _script: &ScriptSource,
        _entry: &str,
        _input: Value,
        _limits: &ScriptLimits,
    ) -> Result<Value, ScriptError> { ... }
}
Expand description

Runs a script.

One call, one entry point, JSON in and JSON out — the same shape a command hook already speaks, so a hook point does not need a second input contract to gain a second backend.

Required Methods§

Source

fn eval<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, script: &'life1 ScriptSource, entry: &'life2 str, input: Value, limits: &'life3 ScriptLimits, ) -> Pin<Box<dyn Future<Output = Result<Value, ScriptError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Call entry in script with input.

Implementations must be able to interrupt a script that does not return — see the module docs. limits is passed for that reason, not so the engine can decide whether to honor it; the carrier enforces the same budget from outside regardless.

Provided Methods§

Source

fn eval_blocking( &self, _script: &ScriptSource, _entry: &str, _input: Value, _limits: &ScriptLimits, ) -> Result<Value, ScriptError>

The same call, from somewhere that cannot await.

Most hook points are synchronous by contract and always will be: a prompt variable provider is a plain Fn, a tool-result transformer takes &self and returns nothing. The calling thread waits for the script, so an engine must not let it wait much past limits.timeout, whatever the script is doing. An engine whose work is genuinely asynchronous should not implement this; the default refuses rather than blocking a runtime from inside itself.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ScriptEngine for RefusingEngine

Source§

impl<F, Fut> ScriptEngine for FnScriptEngine<F>
where F: Fn(&ScriptSource, &str, Value) -> Fut + Send + Sync, Fut: Future<Output = Result<Value, ScriptError>> + Send,