Closed
Description
With this example:
pub trait Iterator<A> {
fn next(&mut self) -> Option<A>;
}
pub trait IteratorUtil<A> {
fn map<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, Self>;
}
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
fn map<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, T> {
MapIterator{iter: self, f: f}
}
}
pub struct MapIterator<'self, A, B, T> {
priv iter: T,
priv f: &'self fn(A) -> B
}
fn main() {
let x = Some(5);
x.map(|x| x.to_str());
}
Option
doesn't implement Iterator, but the following error happens:
foo.rs:22:4: 22:26 error: failed to find an implementation of trait Iterator<<V4>> for <V5>
foo.rs:22 x.map(|x| x.to_str());
^~~~~~~~~~~~~~~~~~~~~~