tokio_retry2/action.rs
1use std::future::Future;
2
3use crate::error::Error as RetryError;
4
5/// An action can be run multiple times and produces a future.
6pub trait Action {
7 /// The future that this action produces.
8 type Future: Future<Output = Result<Self::Item, RetryError<Self::Error>>>;
9 /// The item that the future may resolve with.
10 type Item;
11 /// The error that the future may resolve with.
12 type Error;
13
14 fn run(&mut self) -> Self::Future;
15}
16
17impl<R, E, T: Future<Output = Result<R, RetryError<E>>>, F: FnMut() -> T> Action for F {
18 type Item = R;
19 type Error = E;
20 type Future = T;
21
22 fn run(&mut self) -> Self::Future {
23 self()
24 }
25}