Macro memorize

Source
macro_rules! memorize {
    (
        @inner [$map:ident, $Map:ty, $init:expr]
        fn $name:ident ($($args:ident: $argsty:ty),* $(,)?) -> $ret:ty $body:block
    ) => { ... };
    (fn $name:ident ($($args:ident: $argsty:ty),* $(,)?) -> $ret:ty $body:block) => { ... };
}
Expand description

Automatic memorization for recursive functions.

This macro binds memorized version of the recursive functions to a local variable. The specification of the function declaration part is the same as crecurse.

ยงExample

memorize!(
    fn comb(n: usize, r: usize) -> usize {
        if r > n {
            0
        } else if r == 0 || r == n {
            1
        } else {
            comb!(n - 1, r) + comb!(n - 1, r - 1)
        }
    }
);
assert_eq!(comb(30, 12), 86493225);