3 releases
0.1.2 | May 12, 2019 |
---|---|
0.1.1 | May 11, 2019 |
0.1.0 | May 11, 2019 |
#1746 in Rust patterns
5KB
Map retry
A zero dependency trait that provides map_retry
function on top of native iterators.
Map retry crate provides a trait that allows to repeat mapping on failed results. This is useful for doing IO such as loading webpages using iterators.
use map_retry::MapRetry;
fn retry() {
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let res: Vec<_> = a.iter().map_retry(|a| do_failable_io(a)).collect();
assert_eq!(a.len(), res.len());
}
lib.rs
:
Map retry crate provides a trait that allows to repeat mapping on failed results. This is useful for doing I/O such as loading webpages using iterators.
map_retry
behaves like normal map function, with exception that return type
must be Result
and if Err
is returned it tries to execute mapping function
one more time after all original items have been processed. Order of results is
not guaranteed. If mapping fails also on second try the last error is returned.
The same number of input and output items is guaranteed.
use map_retry::MapRetry;
#
fn retry() {
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let res: Vec<_> = a.iter().map_retry(|a| do_failable_io(a)).collect();
assert_eq!(a.len(), res.len());
}