I have 3 crates.
trait-def
with a trait definition :pub trait Test { type Exec; }
under
with a first implementation of the trait for a type
pub struct First;
pub struct FirstArgument;
impl Test for First {
type Exec = FirstArgument;
}
over
with a second implementation of the trait for another type
pub struct Second;
pub struct SecondArgument;
impl Test for Second {
type Exec = SecondArgument;
}
Until here, everything is alright.
However, when trying to implement a simple From
, things go sideways :
impl From<<First as Test>::Exec> for SecondArgument {
fn from(value: <First as Test>::Exec) -> Self {
Self
}
}
It says :
error[E0119]: conflicting implementations of trait `std::convert::From<SecondArgument>` for type `SecondArgument`
|
13 | impl From<<First as Test>::Exec> for SecondArgument {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> std::convert::From<T> for T;
This is a very simplified example and I can’t just implement From<FirstArgument> for SecondArgument
for unrelated reasons.
I know you have to be careful about implementations of From with traits, but here everything is set in stone, I’m not using generic types. Does someone have an answer as to why this is not accepted in Rust ? Thank you !
New contributor
user24880028 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.