#Issues converting between generic forms of a struct

2 messages · Page 1 of 1 (latest)

robust marsh
#

I'm trying to implement the From trait for conversion between generic forms of a struct, as in something like:

struct SomeStruct<T: SomeTrait>(u64);

impl<T: SomeTrait, F: SomeTrait> From<SomeStruct<F>> for SomeStruct<T> {
    fn from(value: SomeStruct<F>) -> Self {
        SomeStruct::<T>(value.0)
    }
}

however, compiling results in this error:

error[E0119]: conflicting implementations of trait `From<SomeStruct<_>>` for type `SomeStruct<_>`
  --> src\time.rs:86:1
   |
86 | impl<T: SomeTrait, F: SomeTrait> From<SomeStruct<F>> for SomeStruct<T> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: conflicting implementation in crate `core`:
           - impl<T> From<T> for T;

It seems to be due to the default impl<T> From<T> for T no-op, which is kind of annoying sense I'm not trying to subvert that, just add more around it.
Is there some way to exclude the case where T==F? The set of types that implement SomeTrait aren't necessarily finite.

river lance