-
-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
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
anyhow::Error does not implement std::error::Error #136
Comments
This is intentional. That impl would be incoherent with the existing pair of impls error[E0119]: conflicting implementations of trait `std::convert::From<anyhow::Error>` for type `anyhow::Error`:
--> src/error.rs:313:1
|
313 | / impl<E> From<E> for Error
314 | | where
315 | | E: std::error::Error + Send + Sync + 'static,
316 | | {
... |
320 | | }
321 | | }
| |_^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T; |
Thanks for the explanation! I haven't given this much thought, but couldn't you have some function of the type `anyhow::Error -> impl std::error::Error`, which is consistent with the current Deref implementation?
火, 1月 12, 2021 at 19:53, David Tolnay <notifications@github.com> が送信:
… This is intentional. That impl would be incoherent with the existing pair of impls impl From<T> for T (libcore) and impl<E> From<E> for anyhow::Error where E: std::error::Error + Send + Sync + 'static (? support).
error[E0119]: conflicting implementations of trait `std::convert::From<anyhow::Error>` for type `anyhow::Error`:
--> src/error.rs:313:1
|
313 | / impl<E> From<E> for Error
314 | | where
315 | | E: std::error::Error + Send + Sync + 'static,
316 | | {
... |
320 | | }
321 | | }
| |_^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#136 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AFINPUHSXCTTKTIX6QLZW73SZSSFLANCNFSM4V7WXUZA).
|
You can generate such a function using thiserror: use thiserror::Error;
#[derive(Error, Debug)]
#[error(transparent)]
struct Error(anyhow::Error); Now |
Thanks!
火, 1月 12, 2021 at 20:55, David Tolnay <notifications@github.com> が送信:
… You can generate such a function using [thiserror](https://github.com/dtolnay/thiserror):
use
thiserror
::
Error;
#[derive(Error, Debug)]
#[error(transparent)]
struct
Error
(anyhow
::
Error);
Now Error(...) is a function with the signature anyhow::Error -> impl std::error::Error where the resulting error impl has a source/display/backtrace consistent with the argument.
—
You are receiving this because you authored the thread.
Reply to this email directly, [view it on GitHub](#136 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AFINPUCGMBCOKQGFRJ7DMRTSZSZNFANCNFSM4V7WXUZA).
|
Why I understand the technical reason why the Rust compiler wouldn't allow At the moment the However, downstream, when another developer needs to use a library that relies on So, any error is easily gobbled up into an Thus, could we find a compromise where (Or at least a workaround for other "great error library" implementers out there?) |
Is this an oversight or is there some inherent limitation that causes this?
Thanks
The text was updated successfully, but these errors were encountered: