Attribute macro that expands function definition to `RecurFn` implementation.
Opened this issue · 0 comments
Jason5Lee commented
I think it's a good idea to have a attribute macro, which, for example, expands
#[recur_fn]
fn fact(n: u64) -> u64 {
if n == 0 { 1 } else { n * fact(n - 1) }
};
to
struct Fact {}
impl RecurFn<u64, u64> for Fact {
#[inline]
fn body(&self, fact: impl Fn(u64) -> u64, n: u64) -> u64 {
if n == 0 { 1 } else { n * fact(n - 1) }
}
}
static FACT: Fact = Fact {};
fn fact(n: u64) -> u64 {
FACT.call(n)
}