I am stumped everywhere I look it says that I can declare a let x = x.clone() for a string inside the async move and then use that x afterwards without getting the errors used after move or borrowed after move, but that's not working at all.
Don't look too close at the code below as it's been trimmed down to remove unnecessary pieces and I may have accidentally removed something necessary. I've included it to give an idea of the structure. I can't figure out why the clone doesn't prevent the use after move or borrow after move. FYI - using tokio for this.
pub async fn new_article(
tags:Vec<tags>,
author: String,
IP: String,
) -> bool {
let author_id = task::spawn(async move {
let IP = IP.clone();
get_author_id(
IP.clone(),
)
.await
})
.await
.unwrap();
for tag in tags {
let IP=IP.clone();
let docs = task::spawn(async move {
let IP = IP.clone();
get_tag_id( IP.clone(), port).await
})
.await
.unwrap();
match docs {
Ok(v) => match v {
Some(val) => {
let x = val.get_object_id("_id").unwrap().clone();
ids.push(x);
}
None => {
let new_tag = ntag.clone();
let new = task::spawn(async move {
let IP = IP.clone();
insert_one(
IP.clone(),
port,
)
.await
})
.await
.unwrap();
}
},
Err(_e) => missing.push(ntag),
}
}