2 个稳定版本
使用旧的 Rust 2015
| 1.0.1 | 2019 年 1 月 25 日 |
|---|
#2529 在 Rust 模式
9KB
erroneous - 定义和使用错误的辅助工具
erroneous 是一个具有两个功能的 crate
- 它的
Error特征 - 它的
Errorderive
示例
#[macro_use]
extern crate derive_more;
#[macro_use]
extern crate erroneous;
#[derive(Debug, Display, Error)]
enum ParseError {
#[display(fmt = "Found an unexpected 'a' in the input")]
UnexpectedA,
#[display(fmt = "Found an unexpected 'b' in the input")]
UnexpectedB,
#[display(fmt = "Input was empty")]
Empty,
}
The Error 特征
The Error 特征是 std::error::Error 的超特征。它自动为所有实现 std::error::Error 的类型实现,有一些限制,特别是它必须是 Send + Sync + 'static。这意味着在处理它们时你有更多的自由,并且可以将 dyn Error 向下转换为具体类型。此外,该特征还包括一个迭代错误链的辅助方法,称为 iter。
The Error derive
此功能只是为您实现了 std::error::Error(因此也实现了 erroneous::Error),您可以在输入字段上注解为 #[error)] 以使 source 方法返回该字段。
许可证
erroneous 根据您选择的 MIT 许可证或 Apache 许可证 2.0 许可。
依赖关系
~2MB
~46K SLoC