Skip to main content

ResultWrapper

Struct ResultWrapper 

Source
pub struct ResultWrapper<'a, T, E: 'a> { /* private fields */ }
Expand description

Wrapper for Result returned from methods on EaseOff.

Retryable errors will be stored in the EaseOff to be returned on the next attempt if the deadline has passed.

Implementations§

Source§

impl<'a, T, E: 'a> ResultWrapper<'a, T, E>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a, T, E> !UnwindSafe for ResultWrapper<'a, T, E>

§

impl<'a, T, E> Freeze for ResultWrapper<'a, T, E>
where T: Freeze, E: Freeze,

§

impl<'a, T, E> RefUnwindSafe for ResultWrapper<'a, T, E>

§

impl<'a, T, E> Send for ResultWrapper<'a, T, E>
where T: Send, E: Send,

§

impl<'a, T, E> Sync for ResultWrapper<'a, T, E>
where T: Sync, E: Sync,

§

impl<'a, T, E> Unpin for ResultWrapper<'a, T, E>
where T: Unpin, E: Unpin,

§

impl<'a, T, E> UnsafeUnpin for ResultWrapper<'a, T, E>
where T: UnsafeUnpin, E: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V