#iterator #retry #added #lib #top #future #items

retryiter

A wrapper lib on top of rust Iterator with added retry support

8 unstable releases (3 breaking)

0.4.4 Feb 26, 2021
0.4.3 Feb 26, 2021
0.3.0 Feb 6, 2021
0.2.0 Jan 31, 2021
0.1.0 Jan 26, 2021

#1374 in Rust patterns

29 downloads per month
Used in cobust

MIT license

30KB
404 lines

RetryIter

Crates.io MIT licensed Actions Status

RetryIter crate adds retry support for all std::iter::Iterator types. It does it by implementing the crate's IntoRetryIter for all std::iter::Iterator. In addition to retries support, the main feature of this crate is to preserve the iterator items during std::future::Future cancellation in asynchronous processing. It is explained with example in Crate's Main Feature section.

Documentation

Documentation of this crate available at doc.rs

Usage

Add this to your Cargo.toml:

[dependencies]
retryiter = "0.4"

Example

use retryiter::{IntoRetryIter};

#[derive(Debug, Clone, PartialEq)]
struct ValueError;

let a = vec![1, 2, 3];

// Initializing retryiter with retry count 1.
// Also defined the error that can occur in while processing the item.
let mut iter = a.into_iter().retries::<ValueError>(1);

for item in &mut iter {
    if item == 3 {
        // Always failing for value 3.
        item.failed(ValueError);
    } else if item < 3 && item.attempt() == 1 {
        // Only fail on first attempt. The item with value 1 or 2 will
        // succeed on second attempt.
        item.failed(ValueError);
    } else {
        // Marking success for all the other case.
        item.succeeded();
    }
}
assert_eq!(vec![(3, ValueError)], iter.failed_items())

License

This project is licensed under the MIT license.

No runtime deps