A simplified way to think about what I am trying to do is type conversions:
pub trait A where Self: Sized {
type B;
fn to_b(self) -> Self::B;
}
// Doesn't compile
pub trait B where Self: Sized, Self::A: A, <Self::A as A>::B = Self {
type A;
fn from_a(a: Self::A) -> Self {
a.to_b()
}
}
I want to make sure that anything that implements A
has a pair that it can be turned into. That pair should be able to call this conversion function (to_b
) as a constructor.
In order for this to make sense the associated type B
must refer to the same type that implements B
. I am not sure what the syntax is for specifying this.
This is very hard to explain in an easy to understand way but I hope the code helps a bit.