Skip to main content

RunSync

Trait RunSync 

Source
pub trait RunSync {
    // Required methods
    fn prepare_sync(&mut self, program: Program) -> Result<u32, Error>;
    fn execute_sync(
        &mut self,
        program_id: u32,
        input: &[u8],
    ) -> Result<Vec<u8>, Error>;
    fn release_sync(&mut self, program_id: u32) -> Result<(), Error>;
    fn get_externals_sync(&mut self) -> Result<Vec<String>, Error>;

    // Provided methods
    fn run_sync<I, O>(
        &mut self,
        program: &TypedProgram<I, O>,
        input: &I,
    ) -> Result<Result<O>, Error>
       where I: Encode,
             O: Decode { ... }
    fn pull_schema_sync(&mut self) -> Result<String, Error> { ... }
    fn shutdown_sync(&mut self) -> Result<(), Error> { ... }
}
Expand description

Synchronous version of the Run trait for runners that don’t block the process.

This trait should only be implemented for runners that:

  • Execute entirely in-memory (like the interpreter)
  • Use internal thread pools for blocking operations (like DuckDB)

Do NOT implement this for runners that perform actual async I/O operations (like network database connections).

Methods take &mut self since synchronous operations may need to mutate internal state (like database connections).

Required Methods§

Source

fn prepare_sync(&mut self, program: Program) -> Result<u32, Error>

Prepares a program for execution and returns its handle.

If the program is invalid, error is returned either now or later by RunSync::execute_sync.

The runner allocates the program_id internally.

Source

fn execute_sync( &mut self, program_id: u32, input: &[u8], ) -> Result<Vec<u8>, Error>

Execute a previously prepared program.

Source

fn release_sync(&mut self, program_id: u32) -> Result<(), Error>

Releases a prepared program, freeing any associated resources. No-op if program_id is not known.

Source

fn get_externals_sync(&mut self) -> Result<Vec<String>, Error>

Returns the set of externals this runner provides.

Externals are named module prefixes (e.g. "std::sql", "std::fs"). The compiler uses these to validate that all external functions referenced by a program are available before execution.

Provided Methods§

Source

fn run_sync<I, O>( &mut self, program: &TypedProgram<I, O>, input: &I, ) -> Result<Result<O>, Error>
where I: Encode, O: Decode,

Run a program.

This is a helper for calls to RunSync::prepare_sync, RunSync::execute_sync, and RunSync::release_sync, with input encoding and output decoding.

Source

fn pull_schema_sync(&mut self) -> Result<String, Error>

Return static schema of this runner as Lutra source code.

Runners can provide implementations for functions that are not part of standard library. This function returns definitions of these functions as Lutra source code.

For example: interpreter can provide fs::read_parquet() and DuckDB runner can provide sql::read_table().

Source

fn shutdown_sync(&mut self) -> Result<(), Error>

Releases any claimed resources.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§