Skip to main content

Runtime

Trait Runtime 

Source
pub trait Runtime: Send + Sync {
    // Required methods
    fn language(&self) -> &'static str;
    fn execute(
        &self,
        source: &str,
        ctx: &ExecContext,
    ) -> Result<ExecOutput, ExecError>;

    // Provided method
    fn auto_run(&self) -> bool { ... }
}
Expand description

A language backend.

The contract is intentionally Unix-y: take a source string, return stdout / stderr / exit-status / duration. Errors bubble up through ExecError.

Implementations must honour ctx.timeout. If your runtime can’t be cancelled cooperatively, wrap the work in crate::sandbox::with_timeout which spawns the work on a separate thread and drops the channel on overrun.

Required Methods§

Source

fn language(&self) -> &'static str

The fence info-string this runtime claims. Matched case-insensitively against ```<lang>.

Source

fn execute( &self, source: &str, ctx: &ExecContext, ) -> Result<ExecOutput, ExecError>

Run source and return what happened. Returning Ok with a non-zero ExitStatus signals a user-level error (the script ran but crashed); returning Err signals an infrastructure error (timeout, OOM, missing toolchain).

Provided Methods§

Source

fn auto_run(&self) -> bool

Whether blocks using this runtime should auto-run on every page load without requiring the auto-run:: block property.

Auto-run runtimes are also excluded from manual gx execution — their results depend on external state (the workspace, not just the fence body), so a manual re-run provides no additional value over the automatic one.

Default: false. The query runtime returns true.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§