Crates.io | retryiter |
lib.rs | retryiter |
version | 0.4.4 |
source | src |
created_at | 2021-01-26 19:28:16.218691 |
updated_at | 2021-02-26 11:00:34.494897 |
description | A wrapper lib on top of rust Iterator with added retry support |
homepage | |
repository | https://github.com/VigneshChennai/retryiter |
max_upload_size | |
id | 346995 |
size | 32,672 |
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 of this crate available at doc.rs
Add this to your Cargo.toml
:
[dependencies]
retryiter = "0.4"
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())
This project is licensed under the MIT license.