hyperlight_common/func/
functions.rs1use super::utils::for_each_tuple;
5use super::{Error, ParameterTuple, ResultType, SupportedReturnType};
6
7pub trait Function<Output: SupportedReturnType, Args: ParameterTuple, E: From<Error>> {
8 fn call(&self, args: Args) -> Result<Output, E>;
9}
10
11macro_rules! impl_function {
12 ([$N:expr] ($($p:ident: $P:ident),*)) => {
13 impl<F, R, E, $($P),*> Function<R::ReturnType, ($($P,)*), E> for F
14 where
15 F: Fn($($P),*) -> R,
16 ($($P,)*): ParameterTuple,
17 R: ResultType<E>,
18 E: From<Error> + core::fmt::Debug,
19 {
20 fn call(&self, ($($p,)*): ($($P,)*)) -> Result<R::ReturnType, E> {
21 (self)($($p),*).into_result()
22 }
23 }
24 };
25}
26
27for_each_tuple!(impl_function);