use std::fmt::Debug;
use std::future::Future;
use anyhow::Result;
use futures::future::BoxFuture;
use wasmtime::component::{InstancePre, Linker};
pub type FutureResult<T> = BoxFuture<'static, Result<T>>;
pub trait State: Clone + Send + Sync + 'static {
type StoreCtx: Send;
#[must_use]
fn store(&self) -> Self::StoreCtx;
fn instance_pre(&self) -> &InstancePre<Self::StoreCtx>;
}
pub trait Host<T>: Debug + Sync + Send {
fn add_to_linker(linker: &mut Linker<T>) -> Result<()>;
}
pub trait Server<S: State>: Debug + Sync + Send {
#[allow(unused_variables)]
fn run(&self, state: &S) -> impl Future<Output = Result<()>> {
async { Ok(()) }
}
}
pub trait Backend: Sized + Sync + Send {
type ConnectOptions: FromEnv;
#[must_use]
fn connect() -> impl Future<Output = Result<Self>> {
async { Self::connect_with(Self::ConnectOptions::from_env()?).await }
}
fn connect_with(options: Self::ConnectOptions) -> impl Future<Output = Result<Self>>;
}
pub trait FromEnv: Sized {
fn from_env() -> Result<Self>;
}