Hi! I have a problem where I am computing an infinite sequence of things and checking them against subsequent elements in the sequence. Computing the things themselves is expensive (it’s a cryptographic hash) so I’m trying to use
itertools::multipeek to “precompute” them and then re-reveal them later. The natural way to loop over the future ones would be using an iterator, so I’m trying to wrap this
peek method in my own iterator. Unfortunately, I can’t get the lifetimes to work out.
I’ve put together an MCVE at https://play.rust-lang.org/?gist=c6c10a02af83c2ba9b949d3ff6b3bc79&version=stable&backtrace=0 . Instead of using the itertools crate, I’m just using
Peekable::peek() from the stdlib.
Compiling, I get “cannot infer an appropriate lifetime for autoref due to conflicting requirements”. What’s going on? I thought the lifetime of the return value of
peek() would be the lifetime of the
Peekable, which has a lifetime determined by the parameter to the
'a in this example). But it seems like the compiler is trying to tie it to the lifetime of the
PeekFuture reference (
'b), which I don’t think is the same thing? So how do I fix it?