且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何为所有现有错误实现错误包装器?

更新时间:2023-12-05 13:34:22

一篇关于它.要为您的错误获得一流的支持,您需要做两件事:

There's an excellent post about it. To get first-class support for your error you need to do two things:

  • 实现Error trait 适合您的类型.
  • 为要与 ? 运算符(quick_error crate 有助于自动执行此操作.
  • Implement the Error trait for your type.
  • Implement std::convert::From for error types you want to use seamlessly with the ? operator (the quick_error crate helps automate this).