I'm trying to pass a function as the parameter to a map()
call for a future, but I keep getting an error that one of my variables does not live long enough.
fn parse_logs(log_chunk: Chunk) -> Box<Stream<Item=RequestMessage, Error=hyper::Error>> {
let log_str = String::from_utf8(log_chunk.to_vec()).unwrap();
let req_stream = log_str.lines().map(move |line| { ... });
Box::new(stream::iter_ok(req_stream.filter(move |m| m.is_some()).map(move |o| o.unwrap())))
}
I get the following error:
error[E0597]: `log_str` does not live long enough
--> src/http_server.rs:53:9
|
53 | log_str.lines().map(move |line| {
| ^^^^^^^ borrowed value does not live long enough
...
78 | }
| - borrowed value only lives until here
|
= note: borrowed value must be valid for the static lifetime...
I believe this is because I'm trying to use it in a future, but have created a temporary variable in a function being passed as a parameter to map()
and that requires a static lifetime; but I also could be completely wrong about that
Any help here would be greatly appreciated!
Full code can be found here: https://github.com/wspeirs/logstore/blob/dd2ad362da04b7f3cc47ed126ce3500f4bdf0aab/src/http_server.rs#L48