Macro skip_error::skip_error_and_log[][src]

macro_rules! skip_error_and_log {
    ($result : expr, $log_level : expr) => { ... };
}
Expand description

skip_error_and_log returns the value of a Result or log and continues the loop.

skip_error_and_log macro takes two parameters. The first argument is of type Result. The second argument is anything that can be turned into tracing::Level and defines the level to log to. The macro returns the value if Result::Ok and else, it logs the Result::Err and calls continue.

For example

for string_number in &["1", "2", "three", "4"] {
  let number: u32 = skip_error_and_log!(string_number.parse(), tracing::Level::WARN);
}
testing_logger::validate(|captured_logs| {
  assert!(captured_logs[0].body.contains("invalid digit found in string"));
  assert_eq!(captured_logs[0].level, log::Level::Warn);
});