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

log_err

使用 log crate 记录 Unwrap 和 Expect 的错误消息

4 个稳定版本

1.1.1 2021 年 4 月 25 日
1.0.1 2021 年 4 月 14 日
1.0.0 2021 年 4 月 12 日

Rust 模式 中排名第 1208

Download history 20/week @ 2024-03-11 35/week @ 2024-03-18 26/week @ 2024-03-25 45/week @ 2024-04-01 19/week @ 2024-04-08 14/week @ 2024-04-15 31/week @ 2024-04-22 21/week @ 2024-04-29 13/week @ 2024-05-06 17/week @ 2024-05-13 39/week @ 2024-05-20 33/week @ 2024-05-27 57/week @ 2024-06-03 58/week @ 2024-06-10 32/week @ 2024-06-17 20/week @ 2024-06-24

每月下载量 173
2 crates 中使用

无许可协议

7KB
65

Crates.io License Docs

Log_Err

log crate 的小型扩展,它提供了两个方法用于 core::result::Result<T, E>core::option::Option<T>

log_exceptlog_unwrap,在解包/期望 Result/Option 的同时,还会调用 log::error! 宏(在 Result::Err/Option::None 的情况下)。

缩写为

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

示例

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

依赖项

~88KB