0

Suppose I have the following structs:

pub struct Foo {
    pub i: i32
}

pub struct Bar<'a> {
    pub foo: &'a Foo
}

impl<'a> Bar<'a> {
    fn make_baz(&self) -> Baz {
        Baz { bar: self }
    }
}

pub struct Baz<'a, 'b: 'a> {
    pub bar: &'a Bar<'b>
}

Is it possible to impl an Iterator like:

impl<'a> Iterator for Bar<'a> {

    // how do I get this lifetime in here?
    type Item = Baz<_, 'a>;

    fn next(&mut self) -> Option<Self::Item> {
        Some(self.make_baz())
    }
}
Jacob Brown
  • 7,221
  • 4
  • 30
  • 50
  • Short version: No, you cannot return a reference based on `self` as part of the `Iterator` trait. [Another question with good answers](http://stackoverflow.com/q/30422177/155423). – Shepmaster Mar 10 '16 at 19:24
  • @Shepmaster, okay, thanks for the links! – Jacob Brown Mar 10 '16 at 19:48

0 Answers0