Struct retry_error::RetryError

source ·
pub struct RetryError<E> { /* private fields */ }
Expand description

An error type for use when we’re going to do something a few times, and they might all fail.

To use this error type, initialize a new RetryError before you start trying to do whatever it is. Then, every time the operation fails, use RetryError::push() to add a new error to the list of errors. If the operation fails too many times, you can use RetryError as an Error itself.

Implementations§

source§

impl<E> RetryError<E>

source

pub fn in_attempt_to<T: Into<String>>(doing: T) -> Self

Create a new RetryError, with no failed attempts.

The provided doing argument is a short string that describes what we were trying to do when we failed too many times. It will be used to format the final error message; it should be a phrase that can go after “while trying to”.

This RetryError should not be used as-is, since when no Errors have been pushed into it, it doesn’t represent an actual failure.

source

pub fn push<T>(&mut self, err: T)
where T: Into<E>,

Add an error to this RetryError.

You should call this method when an attempt at the underlying operation has failed.

source

pub fn sources(&self) -> impl Iterator<Item = &E>

Return an iterator over all of the reasons that the attempt behind this RetryError has failed.

source

pub fn len(&self) -> usize

Return the number of underlying errors.

source

pub fn is_empty(&self) -> bool

Return true if no underlying errors have been added.

source

pub fn dedup_by<F>(&mut self, same_err: F)
where F: Fn(&E, &E) -> bool,

Group up consecutive errors of the same kind, for easier display.

Two errors have “the same kind” if they return true when passed to the provided dedup function.

source§

impl<E: PartialEq<E>> RetryError<E>

source

pub fn dedup(&mut self)

Group up consecutive errors of the same kind, according to the PartialEq implementation.

Trait Implementations§

source§

impl<E: Clone> Clone for RetryError<E>

source§

fn clone(&self) -> RetryError<E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<E: Debug> Debug for RetryError<E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<E: AsRef<dyn Error>> Display for RetryError<E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError>

Formats the value using the given formatter. Read more
source§

impl<E: Debug + AsRef<dyn Error>> Error for RetryError<E>

1.30.0 · source§

fn source(&self) -> Option<&(dyn Error + 'static)>

The lower-level source of this error, if any. Read more
1.0.0 · source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type based access to context intended for error reports. Read more
source§

impl<E, T> Extend<T> for RetryError<E>
where T: Into<E>,

source§

fn extend<C>(&mut self, iter: C)
where C: IntoIterator<Item = T>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<E> IntoIterator for RetryError<E>

§

type Item = E

The type of the elements being iterated over.
§

type IntoIter = IntoIter<E>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<E> Freeze for RetryError<E>

§

impl<E> RefUnwindSafe for RetryError<E>
where E: RefUnwindSafe,

§

impl<E> Send for RetryError<E>
where E: Send,

§

impl<E> Sync for RetryError<E>
where E: Sync,

§

impl<E> Unpin for RetryError<E>
where E: Unpin,

§

impl<E> UnwindSafe for RetryError<E>
where E: UnwindSafe,

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<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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.