use crate::FromTypeMap;
use variadics_please::all_tuples;
#[async_trait::async_trait]
pub trait Callable<Args: FromTypeMap> {
type Out;
async fn call(self, args: Args) -> Self::Out;
}
macro_rules! impl_callable_tuples {
($($param: ident),*) => {
#[allow(
non_snake_case,
reason = "Certain variable names are provided by the caller, not by us."
)]
#[allow(
unused_variables,
reason = "Zero-length tuples won't use some of the parameters."
)]
#[expect(
clippy::allow_attributes,
reason = "This is in a macro, and as such, the below lints may not always apply."
)]
#[async_trait::async_trait]
impl<Func, Fut, O, $($param: FromTypeMap + Send + Sync),*> Callable<($($param,)*)> for Func
where Func: Fn($($param,)*) -> Fut + Send + Sync,
Fut: Future<Output = O> + Send,
{
type Out = O;
#[inline]
async fn call(self, ($($param,)*): ($($param,)*)) -> Self::Out {
(self)($($param,)*).await
}
}
}
}
all_tuples!(impl_callable_tuples, 0, 16, F);