#macro #log #tracing

skip_error

Utility helping skip and log Result::Error in iterations

7 stable releases

3.1.1 Sep 21, 2021
3.0.0 Sep 6, 2021
2.0.0 Jul 19, 2021
1.1.0 May 12, 2021
1.0.0 Mar 23, 2020

#45 in #tracing

Download history 396/week @ 2021-10-03 319/week @ 2021-10-10 313/week @ 2021-10-17 548/week @ 2021-10-24 205/week @ 2021-10-31 262/week @ 2021-11-07 404/week @ 2021-11-14 169/week @ 2021-11-21 415/week @ 2021-11-28 233/week @ 2021-12-05 431/week @ 2021-12-12 173/week @ 2021-12-19 211/week @ 2021-12-26 423/week @ 2022-01-02 293/week @ 2022-01-09 287/week @ 2022-01-16

1,217 downloads per month
Used in 2 crates

MIT license

18KB
283 lines

GitHub Action Status Latest Version

skip_error

skip_error provides a single macro to help ignoring Error that would happen in a loop. See documentation to know more.

Rust version requirement

skip_error 3.0.0 requires Rustc version 1.54 or greater.


lib.rs:

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.

# #[macro_use]
# extern crate skip_error;
# fn main() {
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).

# #[macro_use]
# extern crate skip_error;
use skip_error::SkipError;
# fn main() {
let numbers: Vec<u32> = ["1", "2", "three", "4"]
  .into_iter()
  .map(|string_number| string_number.parse())
  .skip_error()
  .collect();
# }

Features

  • log: emit log message with the standard std::log macro. Disabled by default.
  • tracing: emit traces with the tracing::trace macro. Disabled by default. If both log and tracing are enabled, then log will be ignored since tracing is configured in a compatibility mode with standard log.

Dependencies

~74KB

TJa