Hello! I am writing my pet app and spent a lot of time trying to figure out why this error occurs. I am building a future stream of ip's, which should ping each ip in parrallel, so I guess i must use buffer_unordered on a stream of futures. But compiler complains about variable fetcher4 which is an Arc. I would appreciate any help for this problem. Code snippet:
some_future_stream_of_strings
.map(move |sub| {
let fetcher4 = fetcher3_2.clone();
match Fetcher::parse_link_to_ip(&sub) {
Some(ip) => fetcher4
.ping(ip)
.inspect_err(|err| {
error!("Unreachable sub: {}, err:{}", sub.clone(), err)
})
.map(|ping| ping.ok().map(|p| (sub.clone(), ip, p)))
.boxed(),
None => {
warn!("Failed to parse sub: {}", sub);
futures::future::ready(None).boxed()
}
}
})
.buffer_unordered(conf.batch_size)
error:
error[E0515]: cannot return value referencing local variable `fetcher4`
--> src/main.rs:79:29
|
79 | / ... match Fetcher::parse_link_to_ip(&sub) {
80 | | ... Some(ip) => fetcher4
| | -------- `fetcher4` is borrowed here
81 | | ... .ping(ip)
82 | | ... .inspect_err(|err| {
... |
91 | | ... }
| |_______________________^ returns a value referencing data owned by the current function