#log #log-error #err #expect #message #options #unwrap

log_err

Log error messages from Unwrap and Expect with log crate

4 stable releases

1.1.1 Apr 25, 2021
1.0.1 Apr 14, 2021
1.0.0 Apr 12, 2021

#1319 in Rust patterns

Download history 8/week @ 2024-07-21 111/week @ 2024-07-28 15/week @ 2024-08-04 22/week @ 2024-08-11 9/week @ 2024-08-18 22/week @ 2024-08-25 13/week @ 2024-09-01 22/week @ 2024-09-08 22/week @ 2024-09-15 62/week @ 2024-09-22 51/week @ 2024-09-29 17/week @ 2024-10-06 38/week @ 2024-10-13 36/week @ 2024-10-20 81/week @ 2024-10-27 84/week @ 2024-11-03

240 downloads per month
Used in 2 crates

Unlicense

7KB
65 lines

Crates.io License Docs

Log_Err

A small extension to the log crate, which provides two methods for core::result::Result<T, E> and core::option::Option<T>

log_except and log_unwrap, which invoke the log::error! macro (in case of Result::Err/Option::None) in addition to unwrapping/expecting the Result/Option.

Shorthand for:

something().map_err(|e| error!("{}: {:?}", msg, e)).expect(msg)

Example:

let mut file = File::create("foo.txt").log_expect("Error creating file");
# Error will be logged with the error! macro
[ERROR] Error creating file: Os { code: 2, kind: NotFound, message: "No such file or directory" }

# Main program panic'ing with same message
thread 'main' panicked at 'Error creating file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', test.rs:4:48

Dependencies

~87KB