rusterror-chain

author author     2023-02-17     785

关键词:

参考技术A Error-Chain是rust常用的错误处理库,目的是方便程序员更好的进行程序的错误管理。这就要说到默认库实现有什么不足。

需要为统一一个Error结构体,并且每一个成员都要实现fmt,display,from
具体可以看 这篇文章

使用Error-chain库会通过声明宏的方式自动转换为如下的程序,具体内容可以展开宏
cargo ristc -- -Z unstable-options --pretty=expanded

所以通过这样的方式,就省去了我们大量的时间
最终输出结果为
result is:this is example error 1 foo error

参考资料:
官方文档说明
其他人的例子
https://users.rust-lang.org/t/announcing-error-chain-a-library-for-consistent-and-reliable-rust-error-handling/6133
https://brson.github.io/2016/11/30/starting-with-error-chain