Skip to main content

run

Function run 

Source
pub fn run<A: IVm>(
    module: Module<A>,
    export: &str,
    action: Action<A>,
) -> Result<String, RunError<A>>
Expand description

Evaluates a module once, selects one of its exports, reads or calls it, and renders that one value as JSON. Nothing else in the export object is called or serialized.

module is the shape generated modules expose, Module<A>: pub fn module<A: IVm>(runtime: Any<A>) -> Result<Any<A>, Any<A>>, taking the runtime value and returning the object of all exports, or the value the module threw. Any other result is a generator bug, not an input, and panics. A module holding a function bounds A on IStaticFunction, which naive implements.

export is looked up among the object’s own properties by presence, not by value: an export holding undefined is found, and reading it then fails as JsonError::Undefined. default is one name among them, with no fallback to it: a module without one answers NoExport("default") for it.

A call converts a clone of the selected value with Function::try_from, whose own error is a fresh TypeError, so that RunError::NotCallable holds the value the caller tried to call. It does not go through Any::call, where a value that is not a function would be a thrown TypeError, indistinguishable from the program throwing.