RetryError

Struct 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 duplicate 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)>

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

Source§

type Item = E

The type of the elements being iterated over.
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 56 bytes