use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use crate::error::ModuleError;
use crate::module::Module;
pub(crate) type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
pub(crate) trait Runtime: Send + Sync {
fn start(self: Arc<Self>) -> BoxFuture<'static, Result<(), ModuleError>>;
fn drain(self: Arc<Self>) -> BoxFuture<'static, Result<(), ModuleError>>;
fn stop(self: Arc<Self>) -> BoxFuture<'static, Result<(), ModuleError>>;
fn details(self: Arc<Self>) -> Vec<(String, String)>;
}
impl<M: Module> Runtime for M {
fn start(self: Arc<Self>) -> BoxFuture<'static, Result<(), ModuleError>> {
Box::pin(async move { Module::start(&*self).await })
}
fn drain(self: Arc<Self>) -> BoxFuture<'static, Result<(), ModuleError>> {
Box::pin(async move { Module::drain(&*self).await })
}
fn stop(self: Arc<Self>) -> BoxFuture<'static, Result<(), ModuleError>> {
Box::pin(async move { Module::stop(&*self).await })
}
fn details(self: Arc<Self>) -> Vec<(String, String)> {
Module::details(&*self)
}
}