#![cfg_attr(not(feature = "std"), no_std)]
pub mod binary;
#[cfg(feature = "channel")]
pub mod channel;
#[cfg(feature = "sync")]
mod sync;
#[cfg(feature = "async")]
mod r#async;
#[cfg(feature = "sync")]
pub use sync::SyncRunner;
#[cfg(feature = "async")]
pub use r#async::AsyncRunner;
use lutra_bin::{rr, string, vec};
pub trait Run {
type Error: core::fmt::Debug;
type Prepared;
fn run<I, O>(
&self,
program: &rr::TypedProgram<I, O>,
input: &I,
) -> impl Future<Output = Result<lutra_bin::Result<O>, Self::Error>>
where
I: lutra_bin::Encode,
O: lutra_bin::Decode,
{
async {
let input = input.encode();
let handle = self.prepare(program.inner.clone()).await?;
let output = self.execute(&handle, &input).await?;
Ok(O::decode(&output))
}
}
fn prepare(
&self,
program: rr::Program,
) -> impl Future<Output = Result<Self::Prepared, Self::Error>>;
fn execute(
&self,
program: &Self::Prepared,
input: &[u8],
) -> impl Future<Output = Result<vec::Vec<u8>, Self::Error>>;
fn get_interface(&self) -> impl Future<Output = Result<string::String, Self::Error>> {
async { Ok(string::String::new()) }
}
fn shutdown(&self) -> impl Future<Output = Result<(), Self::Error>> {
async { Ok(()) }
}
}
pub trait RunSync {
type Error: core::fmt::Debug;
type Prepared;
fn run_sync<I, O>(
&mut self,
program: &rr::TypedProgram<I, O>,
input: &I,
) -> Result<lutra_bin::Result<O>, Self::Error>
where
I: lutra_bin::Encode,
O: lutra_bin::Decode,
{
let input = input.encode();
let handle = self.prepare_sync(program.inner.clone())?;
let output = self.execute_sync(&handle, &input)?;
Ok(O::decode(&output))
}
fn prepare_sync(&mut self, program: rr::Program) -> Result<Self::Prepared, Self::Error>;
fn execute_sync(
&mut self,
program: &Self::Prepared,
input: &[u8],
) -> Result<vec::Vec<u8>, Self::Error>;
fn get_interface_sync(&mut self) -> Result<string::String, Self::Error> {
Ok(string::String::new())
}
fn shutdown_sync(&mut self) -> Result<(), Self::Error> {
Ok(())
}
}
pub mod error_codes {
pub const DECODE_ERROR: &str = "DECODE_ERROR";
pub const PROGRAM_NOT_FOUND: &str = "PROGRAM_NOT_FOUND";
pub const EXECUTION_ERROR: &str = "EXECUTION_ERROR";
pub const PREPARE_ERROR: &str = "PREPARE_ERROR";
}