1 个稳定版本
1.0.8 | 2022年6月29日 |
---|
#541 在 调试 中
每月 29 次下载
用于 2 crates
35KB
831 行
RUC
Rust Util Collection,一个简单友好的 error-chain
,附加了很多有用的工具。
使用 error-chain
的痛苦经历催生了这个项目。它可以适应几乎所有场景,无需特殊实现。
[features]
default = ["ansi"]
ansi = []
compact = []
rich = ["uau", "cmd"]
uau = ["nix", "rand"]
cmd = []
文档
make doc
用法
提示:您可以轻松实现自己的
Error
类型。
use ruc::{err::*, *};
#[derive(Debug, Eq, PartialEq)]
struct CustomErr(i32);
fn will_panic() {
let l1 = || -> Result<()> { Err(eg!("The final error message!")) };
let l2 = || -> Result<()> { l1().c(d!()) };
let l3 = || -> Result<()> { l2().c(d!("A custom message!")) };
let l4 = || -> Result<()> { l3().c(d!("ERR_UNKNOWN")) };
let l5 = || -> Result<()> { l4().c(d!(@CustomErr(-1))) };
pnk!(l5());
}
输出示例
非彩色视图
features = ["ansi"]
# 2021-09-09 9:23:56 [pid: 20837] [pidns: 4026531836]
ERROR: ...
|-- file: src/lib.rs
|-- line: 270
`-- column: 9
Caused By: ...
|-- file: src/lib.rs
|-- line: 264
`-- column: 16
Caused By: CustomErr(-1)
|-- file: src/lib.rs
|-- line: 262
`-- column: 44
Caused By: ERR_UNKNOWN
|-- file: src/lib.rs
|-- line: 261
`-- column: 44
Caused By: A custom message!
|-- file: src/lib.rs
|-- line: 260
`-- column: 44
Caused By: ...
|-- file: src/lib.rs
|-- line: 259
`-- column: 69
Caused By: The final error message!
|-- file: src/lib.rs
|-- line: 258
`-- column: 41
彩色视图
# 2021-09-09 9:23:57 [pid: 20909] [pidns: 4026531836]
ERROR: ...
├── file: src/lib.rs
├── line: 270
└── column: 9
Caused By: ...
├── file: src/lib.rs
├── line: 264
└── column: 16
Caused By: CustomErr(-1)
├── file: src/lib.rs
├── line: 262
└── column: 44
Caused By: ERR_UNKNOWN
├── file: src/lib.rs
├── line: 261
└── column: 44
Caused By: A custom message!
├── file: src/lib.rs
├── line: 260
└── column: 44
Caused By: ...
├── file: src/lib.rs
├── line: 259
└── column: 69
Caused By: The final error message!
├── file: src/lib.rs
├── line: 258
└── column: 41
紧凑视图
features = ["compact"]
# 2022-01-12 5:56:13 [pid: 73002] [pidns: NULL] 》INFO: ... 》file: src/lib.rs 》line: 354 》column: 9 》Caused By: ... 》file: src/lib.rs 》line: 354 》column: 33
依赖
~26–690KB
~13K SLoC