I have a rather complicated trait Reversible. However, there are preset implementations of it, and when one implements ReversibleHelper by picking fitting associated types, Reversible is implemented as well.
Howeve I can't get that to work. It seems like, while assigning the associated type of one to the other, that equality is forgotten when I try to pass that type from the function of one type to the other.
trait ReversibleBase: Reversible<Self> {}
trait Reversible<T: ?Sized + ReversibleBase> {
type OneOfTheTypes;
fn one_of_the_fns(x: Self::OneOfTheTypes);
}
trait ReversibleHelper: ReversibleBase
where
HelperTuple<Self>: Reversible<Self>,
{
type Breakpoints;
type Continuity;
type Acceleratable;
}
type HelperTuple<T> = (
<T as ReversibleHelper>::Breakpoints,
<T as ReversibleHelper>::Continuity,
<T as ReversibleHelper>::Acceleratable,
);
//blanket impl
impl<T> Reversible<T> for T
where
T: ReversibleBase + ReversibleHelper,
HelperTuple<T>: Reversible<T>,
{
type OneOfTheTypes = <HelperTuple<T> as Reversible<T>>::OneOfTheTypes;
fn one_of_the_fns(x: Self::OneOfTheTypes) {
<HelperTuple<T> as Reversible<T>>::one_of_the_fns(x);
}
}
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/lib.rs:28:59
|
21 | impl<T> Reversible<T> for T
| - this type parameter
...
28 | <HelperTuple<T> as Reversible<T>>::one_of_the_fns(x);
| ------------------------------------------------- ^ expected `(<... as ReversibleHelper>::Breakpoints, ..., ...)`, found type parameter `T`
| |
| arguments to this function are incorrect
|
= note: expected associated type `<(<T as ReversibleHelper>::Breakpoints, <T as ReversibleHelper>::Continuity, <T as ReversibleHelper>::Acceleratable) as Reversible<T>>::OneOfTheTypes`
found associated type `<T as Reversible<T>>::OneOfTheTypes`
= note: an associated type was expected, but a different one was found
note: associated function defined here
--> src/lib.rs:4:8
|
4 | fn one_of_the_fns(x: Self::OneOfTheTypes);
| ^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous error
Am I doing something wrong? Is this a compiler limitation?
Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
--> src/lib.rs:13:28
|
13 | T::take_yak_helper(value) //error
| ------------------ ^^^^^ expected `YakHelper::YakHelperType`, found `Yak::YakType`
| |
| arguments to this function are incorrect
|
= note: expected associated type `<T as YakHelper<<T as Assoc>::Type>>::YakHelperType`
found associated type `<T as Yak>::YakType`
= note: an associated type was expected, but a different one was found
note: associated function defined here
--> src/lib.rs:19:8
|
19 | fn take_yak_helper(value: Self::YakHelperType);
| ^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to previous error
It seems I really need to get rid of the Bound on ReversibleBase here. I think that is doable in my case, I will just bound usages not to T: ReversibleBase but to T: ReversibleBase + Reversible<T> or I introduce a supertrait bundling the two.