I have a trait MyIter
that can implement Iterator
trait. But I have no idea how to write this in rust. Below is my draft. but it has a compilation error: "type parameter T must be used as the type parameter for some local type ...".
trait MyIter {
type ValueType;
fn has_value(&self) -> bool;
fn advance(&self) -> Wrapper<Self::ValueType>;
}
impl<T: MyIter> Iterator for T { // ERROR: type parameter T must be used as the type parameter for some local type
type Item = Rc<RefCell<T::ValueType>>;
fn next(&mut self) -> Option<Item> {
self.advance().to_option();
}
}
Below still doesn't compile.
trait MyAnotherIter: Iterator {
type ValueType;
type Item = Rc<RefCell<T::ValueType>>; // ERROR: associated type defaults are unstable.
fn has_value(&self) -> bool;
fn advance(&mut self) -> Wrapper<Self::ValueType>;
fn next(&mut self) -> Option<Self::Item> {
self.advance().to_option();
}
}