Add Itertools::intersperse_with by gin-ahirsch · Pull Request #381 · rust-itertools/itertools (original) (raw)
Actually the issue is not just impl Trait
in return position, but impl Trait
in return position for traits. I'm not sure this is even on the map for Rust, as a Trait's interface is expected to be "fixed".
I tried using inherent trait methods (impl dyn Itertools
), but that doesn't like methods with generic type parameters that don't have the restriction of Self: Sized
:
error[E0038]: the trait `Itertools` cannot be made into an object
--> src/lib.rs:2590:9
|
1394 | fn find_position<P>(&mut self, mut pred: P) -> Option<(usize, Self::Item)>
| ------------- method `find_position` has generic type parameters
...
2590 | impl<Item> dyn Itertools<Item=Item> {
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Itertools` cannot be made into an object
I'm not sure why that would be problematic if not invoked from the inherent methods, but it seems that it is.
Even if that would be solved somehow, we cannot invoke generic methods at all though:
error: the `intersperse_with` method cannot be invoked on a trait object
--> src/lib.rs:2467:14
|
2467 | self.intersperse_with(|| element)
| ^^^^^^^^^^^^^^^^
It's interesting that the method can accept self
by value though, considering its type would be dyn Itertools
.