Expand description
This crate provides a single macro to help skipping a error in a loop, possibly logging it.
For example, imagine you have some code like this.
ⓘ
for string_number in &["1", "2", "three", "4"] {
let number: u32 = match string_number.parse() {
Ok(n) => n,
Err(e) => continue,
};
}Then you can use the macro skip_error! to write like this.
ⓘ
for string_number in &["1", "2", "three", "4"] {
let number: u32 = skip_error!(string_number.parse());
}Or even better, use the trait SkipError that extends Iterator and do
the following (essentially equivalent to Iterator::flatten() but see
below for logging abilities).
ⓘ
use skip_error::SkipError;
let numbers: Vec<u32> = ["1", "2", "three", "4"]
.into_iter()
.map(|string_number| string_number.parse())
.skip_error()
.collect();§Logging
If you want the error to be logged, you can use the feature log or the
feature tracing (see Features). See skip_error_and_log!
and SkipError::skip_error_and_log() for more information.
§Features
log: emit log message with the standardstd::logmacro. Disabled by default.tracing: emit traces with thetracing::tracemacro. Disabled by default. If bothlogandtracingare enabled, thenlogwill be ignored sincetracingis configured in a compatibility mode with standardlog.
Macros§
- skip_
error skip_errorreturns the value of aResultor continues a loop.- skip_
error_ and_ debug skip_error_and_debugreturns the value of aResultor log withtracing::Level::DEBUGand continues the loop.- skip_
error_ and_ error skip_error_and_errorreturns the value of aResultor log withtracing::Level::ERRORand continues the loop.- skip_
error_ and_ info skip_error_and_inforeturns the value of aResultor log withtracing::Level::INFOand continues the loop.- skip_
error_ and_ log skip_error_and_logreturns the value of aResultor log and continues the loop.- skip_
error_ and_ trace skip_error_and_tracereturns the value of aResultor log withtracing::Level::TRACEand continues the loop.- skip_
error_ and_ warn skip_error_and_warnreturns the value of aResultor log withtracing::Level::WARNand continues the loop.
Structs§
- Skip
Error Iter - An iterator that ignore errors
Traits§
- Skip
Error - Trait to extend any
Iteratorwhere theIterator::Itemis aResult. This allows to skip errors and keep only theOk()values.