I'm trying to implement an error enum which can contain an error associated with one of our traits like this:
trait Storage {
type Error;
}
enum MyError<S: Storage> {
StorageProblem(S::Error),
}
I have also tried to implement the From
trait to allow construction of MyError
from an instance of a Storage::Error
:
impl<S: Storage> From<S::Error> for MyError<S> {
fn from(error: S::Error) -> MyError<S> {
MyError::StorageProblem(error)
}
}
However this fails to compile:
error[E0119]: conflicting implementations of trait `std::convert::From<MyError<_>>` for type `MyError<_>`:
--> src/lib.rs:9:1
|
9 | impl<S: Storage> From<S::Error> for MyError<S> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
I don't understand why the compiler reckons this has already been implemented. The error message is telling me that there's already an implementation of From<MyError<_>>
(which there is), but I'm not trying to implement that here - I'm trying to implement From<S::Error>
and MyError
is not the same type as S::Error
from what I can see.
Am I missing something fundamental to generics here?