User after move async move task::spawn

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),
        }
    }
        let docs = task::spawn(async move {
            let IP = IP.clone();
            get_tag_id( IP.clone(), port).await
        })

=>

        let ip=ip.clone();
        let docs = task::spawn(async move {

            get_tag_id( ip, port).await
        })

just clone it outside and rename it. try it or provide a minimal example to me.

I had several places where I was cloning, and it looks like in one place I had cloned it inside rather than outside of the move; I also seem to have had way too many clones than necessary in trying to resolve the issue, which cluttered my code.

Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.