[][src]Function recur_fn::from_pointer

pub fn from_pointer<Arg, Output, D>(d: D) -> FromPointer<D> where
    D: Deref,
    D::Target: RecurFn<Arg, Output>, 

Returns a RecurFn implementation from a pointer to RecurFn, i.e. a implementation of Deref whose Target implements RecurFn.

Examples

use recur_fn::{RecurFn, recur_fn, from_pointer};

fn test_fact(fact: impl RecurFn<i32, i32>) {
    assert_eq!(fact.call(5), 120);
}
let box_fact = Box::new(recur_fn(
    |fact, n: i32| {
        if n <= 1 {
            1
        } else {
            n * fact(n - 1)
        }
    },
));
test_fact(from_pointer(box_fact));