Skip to main content

retryable_result/
retryable.rs

1use std::time::{Duration, Instant};
2
3#[allow(clippy::module_name_repetitions)]
4pub trait Retryable
5where
6    Self: Sized,
7{
8    //! put the logic of how to handle recoverable errors into the `wait_time` function
9    //! one of the tests shows the pattern of exponential backoff with a hard cutoff
10    //! but it does not take into account what the recoverable errors were
11    //! another implementation of this trait might look to see if the same recoverable error
12    //! was the common cause and decide to give up if it that is the case
13    type FatalError;
14    fn to_fatal(self) -> Self::FatalError;
15    fn wait_time(
16        &self,
17        my_time: Instant,
18        previous_retriable_failures: &[(Self, Instant)],
19    ) -> Option<Duration>;
20}
21
22#[allow(clippy::module_name_repetitions)]
23#[allow(dead_code)]
24pub enum RetryableResult<T, R, F>
25where
26    R: Retryable<FatalError = F> + Sized,
27    T: Sized,
28    F: Sized,
29{
30    GoodResult(T),
31    Retryable(R),
32    Fatal(F),
33}