dtolnay / dtolnay/anyhow

downcasting on individual context layers

Open
#84 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
6.7k
Forks
224
PR merge metrics
No merged PRs in 30d

Description

Hi, I would like to be able to downcast on the _just_ the topmost layer of the context stack. Looking through the API, it doesn't appear that this is possible. It's nearly possible by using the underlying std::error::Error provided downcasting, instead of the anyhow downcasting, but anyhow wraps the context in a private ContextError. Even if it were public, I still don't think it would be possible since I know the `C` context type I want, but not the `E` error type.

I think I can work around this in a good enough way for my usecase by comparing `my_anyhow_error.downcast_ref::().unwrap().to_string()` to `my_anyhow_error.to_string()`, which gives me a pretty good indication that the first instance of MyType in the stack is the topmost context layer, but I'm curious if it might be a generally useful feature for anyhow.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.