Macro fun

Source
macro_rules! fun {
    ([$($generics:tt)*] |$arg:ident: $arg_type:ty| -> $output:ty $body:block) => { ... };
    ([$($generics:tt)*] |$arg:ident: $arg_type:ty| -> $output:ty where [$($bounds:tt)*] $body:block) => { ... };
}
Expand description

Generates stateless generic UnaryFunction. Ala generic closure.

§Syntax

fun!([generics list] |argument: type| -> type { .. }
fun!([generics list] |argument: type| where [where bounds] -> type { .. }

§Examples

fun!(['a, T: Primitive, I: Iterator<Item=&'a T>] |xs: I| -> T {
    xs.fold(T::ZERO, |acc, v| acc + *v) 
});

With where bounds:

fun!(['a, T, I] |xs: I| -> T where [T: Primitive, I: Iterator<Item=&'a T>] {
    xs.fold(T::ZERO, |acc, v| acc + *v) 
});