在Iterator中使用self

时间:2016-03-10 19:14:00

标签: rust

假设我有以下结构:

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>
}

是否可以像以下那样使用Iterator:

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())
    }
}

0 个答案:

没有答案