[][src]Macro recur_fn::recur_fn

macro_rules! recur_fn {
    ($fn_name:ident ($arg_name:ident: $arg_type:ty) -> $output_type:ty $body:block) => { ... };
}

Expands a function definition to defining a struct, implementing RecurFn for the struct and constructing it. It can be useful if you want a zero-cost RecurFn implementation.

The function should have exactly one argument. impl Traits and generics are not supported.

Examples

use recur_fn::{recur_fn, RecurFn};

let fact = recur_fn!(fact(n: i32) -> i32 {
    if n == 0 { 1 } else { n * fact(n - 1) }
});
assert_eq!(6, fact.call(3));
assert_eq!(0,
    fact.body(|_| 0, 3));