I have a conversion trait and I want to implement something like this:
trait To<T> {
fn to(self) -> T;
}
impl<T, M, U> To<U> for T
where
T: To<M>,
M: To<U>,
{
fn to(self) -> T {
<M as To<U>>::to(<T as To<M>>::to(self))
}
}
But I got this error:
error[E0207]: the type parameter `M` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:5:9
|
5 | impl<T, M, U> To<U> for T
| ^ unconstrained type parameter
For more information about this error, try `rustc --explain E0207`.
And this variant:
trait To {
type Target;
fn to(self) -> Self::Target;
}
impl<T> To for T
where
T: To,
T::Target: To
{
type Target = <T::Target as To>::Target;
fn to(self) -> Self::Target {
}
}
throws this error:
error[E0275]: overflow evaluating the requirement `<T as To>::Target == _`
--> src/main.rs:11:19
|
11 | type Target = <T::Target as To>::Target;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0275`.
Is it possible to flatten nested generic trait implementation?