4 个版本

0.2.1 2024 年 8 月 20 日
0.2.0 2023 年 8 月 24 日
0.1.1 2022 年 7 月 6 日
0.1.0 2021 年 1 月 28 日

#329 in Rust 模式

Download history 18390/week @ 2024-04-30 17192/week @ 2024-05-07 20287/week @ 2024-05-14 16576/week @ 2024-05-21 16313/week @ 2024-05-28 20921/week @ 2024-06-04 19297/week @ 2024-06-11 20387/week @ 2024-06-18 21228/week @ 2024-06-25 15994/week @ 2024-07-02 19378/week @ 2024-07-09 19800/week @ 2024-07-16 19975/week @ 2024-07-23 19518/week @ 2024-07-30 19662/week @ 2024-08-06 23005/week @ 2024-08-13

86,205 每月下载量
19 个crate中使用 (直接使用 4 个)

Apache-2.0/MIT

12KB
141

display-error-chain

一个轻量级的用于显示错误及其来源的库。

示例输出

macro_rules! impl_error {
    // ...
}

// `TopLevel` is caused by a `MidLevel`.
#[derive(Debug)]
struct TopLevel;
impl_error!(TopLevel, "top level", Some(&MidLevel));

// `MidLevel` is caused by a `LowLevel`.
#[derive(Debug)]
struct MidLevel;
impl_error!(MidLevel, "mid level", Some(&LowLevel));

// `LowLevel` is the cause itself.
#[derive(Debug)]
struct LowLevel;
impl_error!(LowLevel, "low level", None);

// Now let's see how it works:
let formatted = display_error_chain::DisplayErrorChain::new(&TopLevel).to_string();
assert_eq!(
    formatted,
    "\
top level
Caused by:
  -> mid level
  -> low level"
);

// Or with `.chain()` helper:
use display_error_chain::ErrorChainExt as _;
let formatted = TopLevel.chain().to_string();
assert_eq!(
    formatted,
    "\
top level
Caused by:
  -> mid level
  -> low level"
);

// Or even with `.into_chain()` helper to consume the error.
use display_error_chain::ErrorChainExt as _;
let formatted = TopLevel.into_chain().to_string();
assert_eq!(
    formatted,
    "\
top level
Caused by:
  -> mid level
  -> low level"
);

许可证:Apache-2.0/MIT

无运行时依赖