title: How do I solve "cannot return value referencing local data" when using threads and async/await?
body: <p>I am learning Rust especially multithreading and async requests in parallel.</p>
  
  <p>I read the documentation and still I do not understand where I made a mistake. I assume I know where, but do not see how to resolve it.</p>
  
  <p><em>main.rs</em></p>
  
  <pre><code>use std::thread;
  
  struct Request {
      url: String,
  }
  
  impl Request {
      fn new(name: &amp;str) -&gt; Request {
          Request {
              url: name.to_string(),
          }
      }
  
      async fn call(&amp;self, x: &amp;str) -&gt; Result&lt;(), Box&lt;dyn std::error::Error&gt;&gt; {
          let resp = reqwest::get(x).await;
          Ok(())
      }
  }
  
  #[tokio::main]
  async fn main() {
      let requests = vec![
          Request::new("https://www.google.com/"),
          Request::new("https://www.google.com/"),
      ];
      let handles: Vec&lt;_&gt; = requests
          .into_iter()
          .map(|request| {
              thread::spawn(move || async {
                  request.call(&amp;request.url).await;
              })
          })
          .collect();
  
      for y in handles {
          println!("{:?}", y);
      }
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0515]: cannot return value referencing local data `request`
    --&gt; src/main.rs:29:35
     |
  29 |               thread::spawn(move || async {
     |  ___________________________________^
  30 | |                 request.call(&amp;request.url).await;
     | |                 ------- `request` is borrowed here
  31 | |             })
     | |_____________^ returns a value referencing data owned by the current function
  </code></pre>
  
  <p><em>Cargo.toml</em></p>
  
  <pre><code>[dependencies]
  reqwest = "0.10.4"
  tokio = { version = "0.2", features = ["full"] }
  </code></pre>