title: Cannot borrow data in an `Arc` as mutable
body: <p>I don't know what to do next. It looks like I misunderstand something, or maybe I have not learned some critical topic.</p>
  <pre><code>use std::sync::Arc;
  
  use reqwest::{Error, Response}; // 0.11.4
  use tokio::sync::mpsc::{self, Receiver, Sender}; // 1.9.0
  
  pub struct Task {
      pub id: u32,
      pub url: String,
  }
  pub enum Message {
      Failure(Task, Error),
      Success(Task, Response),
  }
  
  struct State {
      client: reqwest::Client,
      res_tx: Sender&lt;Message&gt;,
      res_rx: Receiver&lt;Message&gt;,
  }
  
  pub struct Proxy {
      state: Arc&lt;State&gt;,
      max_rps: u16,
      max_pending: u16,
      id: u32,
      parent_tx: Sender&lt;String&gt;,
  }
  
  async fn send_msg&lt;T&gt;(tx: &amp;Sender&lt;T&gt;, msg: T) {
      match tx.send(msg).await {
          Err(error) =&gt; {
              eprintln!(&quot;{}&quot;, error)
          }
          _ =&gt; (),
      };
  }
  
  impl Proxy {
      // Starts loop for input channel
      async fn start_chin(&amp;mut self) -&gt; Sender&lt;Task&gt; {
          let (chin_tx, mut chin_rx) = mpsc::channel::&lt;Task&gt;(self.max_pending as usize + 1 as usize);
          let state_outer = self.state.clone();
  
          tokio::spawn(async move {
              loop {
                  match chin_rx.recv().await {
                      Some(task) =&gt; {
                          let res_tx = state_outer.res_tx.clone();
                          let state = state_outer.clone();
                          tokio::spawn(async move {
                              match state.client.get(&amp;task.url).send().await {
                                  Ok(res) =&gt; send_msg(&amp;res_tx, Message::Success(task, res)).await,
                                  Err(err) =&gt; send_msg(&amp;res_tx, Message::Failure(task, err)).await,
                              }
                          });
                      }
                      None =&gt; (),
                  }
              }
          });
          chin_tx
      }
  
      async fn start_chres(&amp;self) {
          let state = self.state.clone();
  
          tokio::spawn(async move {
              loop {
                  match state.res_rx.recv().await { // LINE PRODUCES ERROR
                      Some(task) =&gt; {}
                      None =&gt; (),
                  }
              }
          });
      }
  }
  
  impl Proxy {
      pub fn new(
          id: u32,
          parent_tx: Sender&lt;String&gt;,
          proxy_addr: &amp;str,
          max_rps: u16,
          max_pending: u16,
      ) -&gt; Result&lt;Self, Error&gt; {
          let client = reqwest::Client::builder();
          if proxy_addr != &quot;none&quot; {
              client = client.proxy(reqwest::Proxy::all(proxy_addr)?)
          }
          let (res_tx, res_rx) = mpsc::channel::&lt;Message&gt;(max_pending as usize + 1 as usize); // TODO: check size
  
          Ok(Proxy {
              id,
              state: Arc::new(State {
                  client: client.build()?,
                  res_tx,
                  res_rx,
              }),
              max_rps,
              max_pending,
              parent_tx,
          })
      }
  }
  </code></pre>
  <pre class="lang-none prettyprint-override"><code>error[E0596]: cannot borrow data in an `Arc` as mutable
    --&gt; src/lib.rs:69:23
     |
  69 |                 match state.res_rx.recv().await {
     |                       ^^^^^^^^^^^^ cannot borrow as mutable
     |
     = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Arc&lt;State&gt;`
  </code></pre>