Deploying From Based On A Feature That Has Self As A Member

I want to be able to convert any iterator to MyType.

impl<T, I: IntoIterator<Item = T>> From<I> for MyType<T>

As in

MyType<T>::from<I: IntoIterator>(iter: I) -> MyType<T>

As one would expect, for MyTypeit makes sense to convert to Iteratorand satisfy IntoIteratoras a sign, and he does.

But it is Fromautomatically implemented reflexively for any type, of course, any type can convert to itself, and it is here that the compiler will bury:

error[E0119]: conflicting implementations of trait 
`std::convert::From<MyType<_>>` for type `MyType<_>`:

My common implementation for all IntoIteratorsconflicts with the default. If Rust did not provide a default value, then it would indeed work, albeit uselessly expensively.

Is there any way to implement a sign for any member IntoIteratorexcept MyType?

+4

Source: https://habr.com/ru/post/1669469/


All Articles