When using anyhow directly, you can add context to any fallible operation using the methods from the anyhow::Context trait, which is implemented for all result types whose error implements std::error::Error. This is very useful feature of anyhow.
But when using http_types::Result, you can't use anyhow::Context, because http_types::Error does not implement std::error::Error.
I can see why it would be problematic to implement std::error::Error for http_types::Error - it looks like it would conflict with some existing trait implementations. And unfortunately, anyhow::Context uses the sealed-trait pattern, so http_types::Error can't implement that trait either.
What do you think about providing identical methods as anyhow::Context directly for http_types::Result, maybe via a trait like http_types::Context, which http_types::Result would implemented?
When using
anyhow
directly, you can add context to any fallible operation using the methods from theanyhow::Context
trait, which is implemented for all result types whose error implementsstd::error::Error
. This is very useful feature of anyhow.But when using
http_types::Result
, you can't useanyhow::Context
, becausehttp_types::Error
does not implementstd::error::Error
.I can see why it would be problematic to implement
std::error::Error
forhttp_types::Error
- it looks like it would conflict with some existing trait implementations. And unfortunately,anyhow::Context
uses the sealed-trait pattern, sohttp_types::Error
can't implement that trait either.What do you think about providing identical methods as
anyhow::Context
directly forhttp_types::Result
, maybe via a trait likehttp_types::Context
, whichhttp_types::Result
would implemented?