Hello I have following simple code and I don't quite understand how to fix it:
async fn get_statuses(
client: reqwest::Client,
url: Url,
tag: String,
from_id: u64,
) -> Result<HashSet<u64>> {
let response = client
// TODO: escape tag
.get(format!("{}/api/v1/timelines/tag/{}", url, tag))
.send()
.await?;
let json: Value = response.json().await?;
Ok(json
.as_array()
.unwrap()
.iter()
.map(|status| status["id"].as_u64().unwrap())
.collect())
}
pub(crate) async fn run(self: Arc<Self>) -> Result<()> {
TokioScope::scope_and_block( {
|s| {
self.instances.iter().for_each(|instance| {
self.tags.iter().for_each(|tag| {
let instance = instance.clone();
let tag = tag.clone();
let client = self.client.clone();
let last_id = self.last_id;
let proc = move || async {
App::get_statuses(
client.clone(),
instance.clone(),
tag.clone(),
last_id,
)
};
s.spawn(proc());
});
});
}
});
Ok(())
}
Getting following error:
72 | let proc = move || async {
| ____________________________________-------_^
| | | |
| | | return type of closure `{async block@src/app.rs:72:44: 79:26}` contains a lifetime `'2`
| | lifetime `'1` represents this closure's body
73 | | App::get_statuses(
74 | | client.clone(),
75 | | instance.clone(),
... |
78 | | )
79 | | };
| |_________________________^ returning this value requires that `'1` must outlive `'2`
Btw TokioScope struct is from async-scoped crate.
How can I pass values to get_statuses method successfully?