[][src]Trait recur_fn::RecurFn

pub trait RecurFn<Arg, Output> {
    fn body(
        &self,
        recur: impl Fn(Arg) -> Output,
        arg: Arg
    ) -> Output; fn call(&self, arg: Arg) -> Output { ... } }

The recursive function trait.

Instead of recurring directly, this trait allows user to customize the recursion by accepting Fn-type parameter. In this way, we can extract and extend the body of the recursive function.

This trait only supports one argument. If you need multiple arguments, use tuple.

Required methods

fn body(
    &self,
    recur: impl Fn(Arg) -> Output,
    arg: Arg
) -> Output

The body of the recursive function.

Performance tip: mark this method #[inline] to make the call method as fast as recurring directly.

Loading content...

Provided methods

fn call(&self, arg: Arg) -> Output

Calls the recursive function.

Loading content...

Implementors

impl<Arg, Output> RecurFn<Arg, Output> for dyn DynRecurFn<Arg, Output>[src]

dyn DynRecurFn implement RecurFn.

impl<Arg, Output> RecurFn<Arg, Output> for dyn DynRecurFn<Arg, Output> + Send[src]

dyn DynRecurFn implement RecurFn.

impl<Arg, Output> RecurFn<Arg, Output> for dyn DynRecurFn<Arg, Output> + Send + Sync[src]

dyn DynRecurFn implement RecurFn.

impl<Arg, Output> RecurFn<Arg, Output> for dyn DynRecurFn<Arg, Output> + Sync[src]

dyn DynRecurFn implement RecurFn.

impl<Arg, Output, '_> RecurFn<Arg, Output> for &'_ (dyn DynRecurFn<Arg, Output> + Send + Sync)[src]

&dyn DynRecurFn implement RecurFn.

impl<Arg, Output, '_> RecurFn<Arg, Output> for &'_ (dyn DynRecurFn<Arg, Output> + Send)[src]

&dyn DynRecurFn implement RecurFn.

impl<Arg, Output, '_> RecurFn<Arg, Output> for &'_ (dyn DynRecurFn<Arg, Output> + Sync)[src]

&dyn DynRecurFn implement RecurFn.

impl<Arg, Output, '_> RecurFn<Arg, Output> for &'_ dyn DynRecurFn<Arg, Output>[src]

&dyn DynRecurFn implement RecurFn.

impl<Arg, Output, F: Fn(Arg) -> Output> RecurFn<Arg, Output> for F[src]

Fn(Arg) -> Outputs implement RecurFn<Arg, Output>. It calls the function directly, without calling recur parameter.

fn call(&self, arg: Arg) -> Output[src]

Loading content...