Trait skip_error::SkipError [−][src]
pub trait SkipError<I, T, E>: Sized where
I: Iterator<Item = Result<T, E>>, {
fn skip_error(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
;
fn skip_error_and_log<L>(self, trace_level: L) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
where
L: Into<Level>;
fn skip_error_and_trace(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
{ ... }
fn skip_error_and_debug(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
{ ... }
fn skip_error_and_error(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
{ ... }
fn skip_error_and_warn(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
{ ... }
fn skip_error_and_info(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
{ ... }
}
Expand description
Trait to extend any Iterator
where the Iterator::Item
is a Result
.
This allows to skip errors and keep only the Ok()
values.
Required methods
fn skip_error(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
fn skip_error(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Skip all errors of the Result
in the original Iterator
.
This is essentially equivalent to .flatten()
.
use skip_error::SkipError;
let v: Vec<usize> = vec![0,1,0,0,3]
.into_iter()
.map(|v|
if v == 0 {
Ok(0)
} else {
Err(format!("Boom on {}", v))
}
)
.skip_error()
.collect();
assert_eq!(v, vec![0,0,0]);
fn skip_error_and_log<L>(self, trace_level: L) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
where
L: Into<Level>,
fn skip_error_and_log<L>(self, trace_level: L) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
where
L: Into<Level>,
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Skip all errors of the Result
in the original Iterator
. This
also allows to log the errors, choosing which tracing::Level
to use.
use skip_error::SkipError;
let v: Vec<usize> = vec![0,1,0,0,3]
.into_iter()
.map(|v|
if v == 0 {
Ok(0)
} else {
Err(format!("Boom on {}", v))
}
)
.skip_error_and_log(tracing::Level::WARN)
.collect();
assert_eq!(v, vec![0,0,0]);
testing_logger::validate(|captured_logs| {
assert_eq!(captured_logs[0].level, log::Level::Warn);
assert_eq!(captured_logs[0].body, "Boom on 1 ");
assert_eq!(captured_logs[1].level, log::Level::Warn);
assert_eq!(captured_logs[1].body, "Boom on 3 ");
});
Provided methods
fn skip_error_and_trace(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
fn skip_error_and_trace(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Shortcut for SkipError::skip_error_and_log
with a log level of tracing::Level::TRACE
.
For example
use skip_error::SkipError;
vec![Ok(1), Ok(2), Err("'three' is not a valid number"), Ok(4)]
.into_iter()
.skip_error_and_trace()
.collect::<Vec<_>>();
testing_logger::validate(|captured_logs| {
assert!(captured_logs[0].body.contains("'three' is not a valid number"));
assert_eq!(captured_logs[0].level, log::Level::Trace);
});
fn skip_error_and_debug(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
fn skip_error_and_debug(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Shortcut for SkipError::skip_error_and_log
with a log level of tracing::Level::DEBUG
.
For example
use skip_error::SkipError;
vec![Ok(1), Ok(2), Err("'three' is not a valid number"), Ok(4)]
.into_iter()
.skip_error_and_debug()
.collect::<Vec<_>>();
testing_logger::validate(|captured_logs| {
assert!(captured_logs[0].body.contains("'three' is not a valid number"));
assert_eq!(captured_logs[0].level, log::Level::Debug);
});
fn skip_error_and_error(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
fn skip_error_and_error(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Shortcut for SkipError::skip_error_and_log
with a log level of tracing::Level::ERROR
.
For example
use skip_error::SkipError;
vec![Ok(1), Ok(2), Err("'three' is not a valid number"), Ok(4)]
.into_iter()
.skip_error_and_error()
.collect::<Vec<_>>();
testing_logger::validate(|captured_logs| {
assert!(captured_logs[0].body.contains("'three' is not a valid number"));
assert_eq!(captured_logs[0].level, log::Level::Error);
});
fn skip_error_and_warn(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
fn skip_error_and_warn(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Shortcut for SkipError::skip_error_and_log
with a log level of tracing::Level::WARN
.
For example
use skip_error::SkipError;
vec![Ok(1), Ok(2), Err("'three' is not a valid number"), Ok(4)]
.into_iter()
.skip_error_and_warn()
.collect::<Vec<_>>();
testing_logger::validate(|captured_logs| {
assert!(captured_logs[0].body.contains("'three' is not a valid number"));
assert_eq!(captured_logs[0].level, log::Level::Warn);
});
fn skip_error_and_info(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
fn skip_error_and_info(self) -> SkipErrorIter<I, T, E>ⓘNotable traits for SkipErrorIter<I, T, E>impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
impl<I, T, E> Iterator for SkipErrorIter<I, T, E> where
I: Iterator<Item = Result<T, E>>,
E: Display, type Item = T;
Shortcut for SkipError::skip_error_and_log
with a log level of tracing::Level::INFO
.
For example
use skip_error::SkipError;
vec![Ok(1), Ok(2), Err("'three' is not a valid number"), Ok(4)]
.into_iter()
.skip_error_and_info()
.collect::<Vec<_>>();
testing_logger::validate(|captured_logs| {
assert!(captured_logs[0].body.contains("'three' is not a valid number"));
assert_eq!(captured_logs[0].level, log::Level::Info);
});