I have a situation similar to the one in this example, where two generic implementations for classes of types that are meant to be disjoint intersect:
trait Types {
type A;
type B;
}
trait MyTrait: Types {
fn transform(&self, a: Self::A) -> Self::B;
}
trait DelegateMyTrait {
type Delegate: MyTrait;
fn delegate(&self) -> &Self::Delegate;
}
impl<T: DelegateMyTrait> Types for T {
type A = <T::Delegate as Types>::A;
type B = <T::Delegate as Types>::B;
}
impl<T: DelegateMyTrait> MyTrait for T {
fn transform(&self, a: Self::A) -> Self::B {
self.delegate().transform(a)
}
}
impl<T> MyTrait for T
where
T: Types<A = <T as Types>::B>,
{
fn transform(&self, a: Self::A) -> Self::B {
a
}
}
Is there some technique that would allow me to avoid separate implementations for each T: Types<A = <T as Types>::B>
?