We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
简单来说就是library用thiserror这个crate, binary工程用anyhow这个crate。
library 一般是给外部调用,所以需要尽可能enum一个对外易懂的错误,因为library的错误是API的一部分,caller需要知道该怎么处理错误,是错误的消费者。所以对于library,尽可能不用这样的返回Boxed错误 Result<String, Box<dyn std::error::Error>> , 目前就是用thiserror了,自己enum出来一些你自定义的Error返回出去,让caller方便处理。至于binary的话,因为再上一层就是终端用户了,用Boxed Error也是可以的,大部分错误都可以不用处理,而是打印日志或者弹出错误框什么的。
Result<String, Box<dyn std::error::Error>>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
简单来说就是library用thiserror这个crate, binary工程用anyhow这个crate。
library 一般是给外部调用,所以需要尽可能enum一个对外易懂的错误,因为library的错误是API的一部分,caller需要知道该怎么处理错误,是错误的消费者。所以对于library,尽可能不用这样的返回Boxed错误
Result<String, Box<dyn std::error::Error>>
, 目前就是用thiserror了,自己enum出来一些你自定义的Error返回出去,让caller方便处理。至于binary的话,因为再上一层就是终端用户了,用Boxed Error也是可以的,大部分错误都可以不用处理,而是打印日志或者弹出错误框什么的。References
The text was updated successfully, but these errors were encountered: