use std::future::Future;
use crate::{callable::SupportsAsync, App, User};
pub trait CallableParam<Ctx, Init>: Send + Sync + Sized {
type Error: std::error::Error + Send;
fn extract(
ctx: &mut Ctx,
init: &Init,
) -> impl Future<Output = Result<Self, Self::Error>> + Send + Sync;
}
pub trait CallableFetch<T>: Send + Sync {
fn fetch(&self) -> T;
}
macro_rules! impl_callable_param_fetch {
($t:ty) => {
impl<Ctx: CallableFetch<$t>, Init: Send + Sync> CallableParam<Ctx, Init> for $t {
type Error = std::convert::Infallible;
async fn extract(ctx: &mut Ctx, _init: &Init) -> Result<Self, Self::Error> {
Ok(ctx.fetch())
}
}
};
}
impl_callable_param_fetch!(User);
impl_callable_param_fetch!(App);
impl SupportsAsync for User {}
impl SupportsAsync for App {}