pub struct ResultWrapper<'a, T, E: 'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a, T, E: 'a> ResultWrapper<'a, T, E>
impl<'a, T, E: 'a> ResultWrapper<'a, T, E>
Sourcepub fn on_timeout(
self,
on_timeout: impl FnOnce(TimeoutError<E>) -> Error<E>,
) -> ResultWrapper<'a, T, E>
pub fn on_timeout( self, on_timeout: impl FnOnce(TimeoutError<E>) -> Error<E>, ) -> ResultWrapper<'a, T, E>
Convert a TimeoutError, if applicable, to another Error variant.
May be used to convert a timeout error into Error::MaybeRetryable.
If not otherwise handled, .or_retry() and .or_retry_if() will return the error.
Sourcepub fn inspect_err(self, inspect_err: impl FnOnce(&Error<E>)) -> Self
pub fn inspect_err(self, inspect_err: impl FnOnce(&Error<E>)) -> Self
Inspect the error if the operation failed.
This could also be Error::TimedOut containing an error from a previous iteration.
Sourcepub fn or_retry(self) -> Result<Option<T>, E>where
E: RetryableError,
pub fn or_retry(self) -> Result<Option<T>, E>where
E: RetryableError,
Check the result, testing the error for retryability using RetryableError if applicable.
If the operation was successful, Ok(Some(_)) is returned.
If the operation failed but RetryableError::can_retry() returned true,
Ok(None) is returned and the error is stored in the EaseOff instance for the next
iteration.
If the error was determined to be fatal or the deadline has elapsed,
Err is returned.
Sourcepub fn or_retry_if(
self,
can_retry: impl FnOnce(&Error<E>) -> bool,
) -> Result<Option<T>, E>
pub fn or_retry_if( self, can_retry: impl FnOnce(&Error<E>) -> bool, ) -> Result<Option<T>, E>
Check the result, testing the error for retryability using the given closure if applicable.
The closure will be invoked with either the error from the current attempt,
or a previous error if the deadline has elapsed
(this is indicated by the Error::TimedOut variant).
If the operation was successful, Ok(Some(_)) is returned.
If the operation failed but the given closure returns true,
Ok(None) is returned and the error is stored in the EaseOff instance for the next
iteration.
If the error was determined to be fatal, Err is returned.
Sourcepub fn or_retry_with(
self,
should_retry: impl FnOnce(&Error<E>) -> ControlFlow<(), Option<Instant>>,
) -> Result<Option<T>, E>
pub fn or_retry_with( self, should_retry: impl FnOnce(&Error<E>) -> ControlFlow<(), Option<Instant>>, ) -> Result<Option<T>, E>
Check the result, testing the error for retryability using the given closure if applicable.
The closure will be invoked with either the error from the current attempt,
or a previous error if the deadline has elapsed
(this is indicated by the Error::TimedOut variant).
If the operation was successful, Ok(Some(_)) is returned.
If the operation failed but the given closure returns ControlFlow::Continue,
Ok(None) is returned and the error is stored in the EaseOff instance for the next
iteration.
If the given error specifies a retry time,
the closure may return Control::Continue(Some(retry_at))
with the next attempt waiting until retry_at or the current backoff,
whichever is later.
Otherwise, the closure should return ControlFlow::Continue(None) to use the
next backoff time.
If the error is fatal, the closure should return ControlFlow::Break(())
and then Err is returned.