retryiter

Crates.ioretryiter
lib.rsretryiter
version0.4.4
sourcesrc
created_at2021-01-26 19:28:16.218691
updated_at2021-02-26 11:00:34.494897
descriptionA wrapper lib on top of rust Iterator with added retry support
homepage
repositoryhttps://github.com/VigneshChennai/retryiter
max_upload_size
id346995
size32,672
Vigneshwaran P (VigneshChennai)

documentation

README

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.

Commit count: 29

cargo fmt