futures_retry

Trait FutureFactory

Source
pub trait FutureFactory {
    type FutureItem: TryFuture;

    // Required method
    fn new(&mut self) -> Self::FutureItem;
}
Expand description

A factory trait used to create futures.

We need a factory for the retry logic because when (and if) a future returns an error, its internal state is undefined and we can’t poll on it anymore. Hence we need to create a new one.

By the way, this trait is implemented for any closure that returns a Future, so you don’t have to write your own type and implement it to handle some simple cases.

Required Associated Types§

Source

type FutureItem: TryFuture

An future type that is created by the new method.

Required Methods§

Source

fn new(&mut self) -> Self::FutureItem

Creates a new future. We don’t need the factory to be immutable so we pass self as a mutable reference.

Implementors§

Source§

impl<T, F> FutureFactory for T
where T: Unpin + FnMut() -> F, F: TryFuture,