A thousand times asked for sure but I wasn't able to figure this out even with an example...
I have this:
pub struct Frames<'a> {
gfx: &'a mut Gfx,
}
impl<'a> Iterator for Frames<'a> {
type Item = Frame<'a>;
fn next(&'a mut self) -> Option<Self::Item> {
Some(Frame{ gfx: self.gfx })
}
}
pub struct Frame<'a> {
pub gfx: &'a mut Gfx
}
And the error is that the lifetime 'a defined on the fn next(&'a mut self) line doesn't necessarily outlive the lifetime 'a defined at impl<'a> Iterator for Frames<'a>. I have a feeling any attempts at specifying the lifetime for self is going to be doomed because of the trait definition but I'm not entirely sure, and if I make it just fn next(&mut self) it says I'm returning a reference with a lifetime of '1 when 'a is expected, so whole another lifetime in that case ๐
I'm not sure I actually understand why with &'a mut self the lifetime is required to outlive the 'a of impl<'a>. I'm probably having two lifetimes with identical names here?
