3 ms·
Oh? Maybe I was looking up the wrong thing. Now that I search again I think this is what I was trying to do: http://stackoverflow.com/questions/30422177/life
by justinsaccount 10y ago
Oh? Maybe I was looking up the wrong thing. Now that I search again I think this is what I was trying to do:
http://stackoverflow.com/questions/30422177/lifetime-in-iterator-impl http://stackoverflow.com/questions/30422177/lifetime-in-iter...
though in my case I had a vec of &str or something like that.
What I do remember was the compiler sending me in circles. Honestly if it had just said something like "Hey dummy, you can't do that, go read the chapters on lifetimes again" I might have fixed it. But it kept telling me things like "Just add a lifetime specifier on this line" and I would do that and then get 2 more error messages. I think the errors sent me down the path of trying to do what the SO post mentions, which is
fn next<'a>(&'a mut self) -> Option<Vec<&'a T>>
instead of putting the lifetime on the impl block, which probably never even occurred to me was something you could do.
- steveklabnik 10y agoAh ha, yes, this is more than just pointers. It's a "streaming" iterator as opposed to just an iterator, and yeah, we need more types, IIRC, before that's possible. As I mentioned below, we love bugs about bad error messages, feel free to file them!
- ckarmann 10y agoWell, if you love this kind of bug reports, please take a look at the one I filed a while ago :) https://github.com/rust-lang/rust/issues/11724 https://github.com/rust-lang/rust/issues/11724 Thanks!
- nercury 10y agoThe idea here is to separate lifetime of iteration (the scope in which "next" is used 'i) and the lifetime of data ('a), which would result in following signature: fn next<'i>(&'i mut self) -> Option<Vec<&'a T>> which, thanks to lifetime elision, is the same as fn next(&mut self) -> Option<Vec<&'a T>>