Skip to main content

RunSync

Trait RunSync 

Source
pub trait RunSync {
    type Error: Debug;
    type Prepared;

    // Required methods
    fn prepare_sync(
        &mut self,
        program: Program,
    ) -> Result<Self::Prepared, Self::Error>;
    fn execute_sync(
        &mut self,
        program: &Self::Prepared,
        input: &[u8],
    ) -> Result<Vec<u8>, Self::Error>;

    // Provided methods
    fn run_sync<I, O>(
        &mut self,
        program: &TypedProgram<I, O>,
        input: &I,
    ) -> Result<Result<O>, Self::Error>
       where I: Encode,
             O: Decode { ... }
    fn get_interface_sync(&mut self) -> Result<String, Self::Error> { ... }
    fn shutdown_sync(&mut self) -> Result<(), Self::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 Associated Types§

Required Methods§

Source

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

Prepares a program for execution and returns a handle, which can be used with RunSync::execute_sync.

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

When the handle is returned, the program might not be fully prepared yet, so first execution of the program might take longer then subsequent RunSync::execute_sync calls.

Source

fn execute_sync( &mut self, program: &Self::Prepared, input: &[u8], ) -> Result<Vec<u8>, Self::Error>

Execute a prepared program synchronously. Program’s format must match the format supported by this runner.

Provided Methods§

Source

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

Run a program.

This is helper function for RunSync::prepare_sync followed by RunSync::execute_sync, with input encoding and output decoding.

Source

fn get_interface_sync(&mut self) -> Result<String, Self::Error>

Return static interface 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<(), Self::Error>

Releases any claimed resources.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§