use std::{error::Error, sync::Arc};
#[cfg(feature = "async")]
use async_trait::async_trait;
#[cfg(feature = "async")]
use crate::wapchost::modulestate_async::ModuleStateAsync;
use crate::{wapchost::modulestate::ModuleState, Invocation};
pub trait ModuleHost {
fn get_guest_request(&self) -> Option<Invocation>;
fn get_host_response(&self) -> Option<Vec<u8>>;
fn set_guest_error(&self, error: String);
fn set_guest_response(&self, response: Vec<u8>);
fn get_host_error(&self) -> Option<String>;
fn do_host_call(
&self,
binding: &str,
namespace: &str,
operation: &str,
payload: &[u8],
) -> Result<i32, Box<dyn Error>>;
fn do_console_log(&self, msg: &str);
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[async_trait]
pub trait ModuleHostAsync {
async fn get_guest_request(&self) -> Option<Invocation>;
async fn get_host_response(&self) -> Option<Vec<u8>>;
async fn set_guest_error(&self, error: String);
async fn set_guest_response(&self, response: Vec<u8>);
async fn get_host_error(&self) -> Option<String>;
async fn do_host_call(
&self,
binding: &str,
namespace: &str,
operation: &str,
payload: &[u8],
) -> Result<i32, Box<dyn Error>>;
async fn do_console_log(&self, msg: &str);
}
pub trait WebAssemblyEngineProvider {
fn init(&mut self, host: Arc<ModuleState>) -> Result<(), Box<dyn Error + Send + Sync>>;
fn call(&mut self, op_length: i32, msg_length: i32) -> Result<i32, Box<dyn Error + Send + Sync>>;
fn replace(&mut self, bytes: &[u8]) -> Result<(), Box<dyn Error + Send + Sync>>;
}
#[cfg(feature = "async")]
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[async_trait]
pub trait WebAssemblyEngineProviderAsync {
async fn init(&mut self, host: Arc<ModuleStateAsync>) -> Result<(), Box<dyn Error + Send + Sync>>;
async fn call(&mut self, op_length: i32, msg_length: i32) -> Result<i32, Box<dyn Error + Send + Sync>>;
async fn replace(&mut self, bytes: &[u8]) -> Result<(), Box<dyn Error + Send + Sync>>;
}