How to implement an error wrapper for all existing Errors?

前端 未结 1 1370
旧时难觅i
旧时难觅i 2020-12-28 19:35

I want to use my customised error type in all functions and I need to wrap the existing standard errors so that the ? operator will succeed.

Here is wha

相关标签:
1条回答
  • 2020-12-28 20:23

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

    • 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).
    0 讨论(0)
提交回复
热议问题