I have an Iterator trait defined like this:
pub trait IteratorImpl : PartialEq {
type distance_type_impl : Integer;
fn increment_impl(&mut self);
fn successor_impl(mut self) -> Self where Self : Sized {
self.increment_impl();
self
}
}
I need to define addition and subtraction on iterators, but as the Add and Sub traits are defined in a different module, I need to wrap this iterator. I am using:
#[derive(Clone, PartialEq, Debug)]
pub struct It<I>(pub I);
Now I want to define an Iterator that only works on It<_> types, so I have a another trait:
pub trait Iterator : PartialEq + Add + Sub + Sized {
type distance_type : Integer;
fn increment(&mut self);
fn successor(mut self) -> Self where Self : Sized {
self.increment();
self
}
}
and I then want to define a single implementation for this new Iterator trait:
impl<I> Iterator for It<I> where I : IteratorImpl {
type distance_type = I::distance_type_impl;
fn increment(&mut self) {
self.0.increment_impl();
}
}
However I get this error when compiling
type mismatch resolving `<I as elements::IteratorImpl>::distance_type_impl == elements::It<I>`:
expected associated type,
found struct `elements::It`type mismatch resolving `<I as elements::IteratorImpl>::distance_type_impl == elements::It<I>`:
expected associated type,
found struct `elements::It` [E0271 []E0271]
I don't understand why I cannot forward the associated type from Iterator to the wrapped associated type on the Iterator in the It<_> wrapper.
Edit: I copied and pasted these bits plus a few definitions into the Rust Playground, and I did not get an error, so I think some other definition must be causing the problem being reported.