http-rs / http-rs/http-types

Allow adding context to Result similarly to other Result types

Open
#367 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
209
Forks
91
PR merge metrics
No merged PRs in 30d

Description

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.

```rust
my_fallible_operation()
.await
.context("my fallible operation failed")?;
```

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.