Hacker News new | past | comments | ask | show | jobs | submit login

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



Ah 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!


Well, 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

Thanks!


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




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: