1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
macro_rules! impl_trait_n_args {
( $($var:ident: $typevar:ident),* ) => (
impl<$($typevar,)* Result, F: FnOnce($($typevar),*) -> Result> FnBox<($($typevar,)*), Result> for F {
fn call(self: Box<Self>, ($($var,)*): ($($typevar,)*)) -> Result {
let this : Self = *self;
this($($var),*)
}
}
)
}
macro_rules! build_n_args {
( $name:ident [$($add:tt)*]: $($var:ident: $typevar:ident),* ) => (
impl< $($typevar,)* Result> $name<($($typevar,)*), Result> {
#[inline]
pub fn call(self $(, $var: $typevar)*) -> Result {
FnBox::call(self.0, ($($var ,)*))
}
}
impl< $($typevar,)* Result, F: 'static + FnOnce($($typevar),*) -> Result $($add)*> From<F> for $name<($($typevar,)*), Result> {
fn from(func: F) -> Self {
$name(Box::new(func) as Box<FnBox<($($typevar,)*), Result> $($add)*>)
}
}
)
}