use std::marker::PhantomData;
trait Origin {
const ORIGIN: i32;
}
struct Zero;
impl Origin for Zero {
const ORIGIN: i32 = 0;
}
struct Hundred;
impl Origin for Hundred {
const ORIGIN: i32 = 100;
}
struct Value<ORIGIN> {
x: i32,
origin: PhantomData<ORIGIN>,
}
impl<ORIGIN1: Origin, ORIGIN2: Origin> From<Value<ORIGIN1>> for Value<ORIGIN2> {
fn from(v: Value<ORIGIN1>) -> Self {
Self {
x: v.x,
origin: PhantomData,
}
}
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0119]: conflicting implementations of trait `From<Value<_>>` for type `Value<_>`
--> src/lib.rs:22:1
|
22 | impl<ORIGIN1: Origin, ORIGIN2: Origin> From<Value<ORIGIN1>> for Value<ORIGIN2> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> From<T> for T;
For more information about this error, try `rustc --explain E0119`.
error: could not compile `playground` due to previous error
I have already found this issue but is there any clear way forward that may allow the case where ORIGIN1 != ORIGIN2
?