title: the trait `std::marker::Copy` is not implemented for Type
body: <p>I'm trying to move some data around b/w different threads but am getting the ole Copy trait-not-implemented error. Here's some code:</p>
  <pre><code>use std::future::Future;
  use std::marker::PhantomData;
  use std::sync::{Arc, Mutex};
  
  /// Start external crates mocked here
  
  #[derive(Clone, PartialEq, Eq)]
  pub struct DecodeError {
      inner: Box&lt;Inner&gt;,
  }
  #[derive(Clone, PartialEq, Eq)]
  struct Inner {}
  #[derive(Clone)]
  pub struct Connection {}
  
  pub trait Message: core::fmt::Debug + Send + Sync {
      fn decode&lt;B&gt;(mut buf: B) -&gt; Result&lt;Self, DecodeError&gt;
      where
          B: bytes::Buf,
          Self: Default,
      {
          // do stuff
          let mut message = Self::default();
          Ok(message)
      }
  }
  
  #[derive(Clone, Debug, Default)]
  pub struct Request {}
  impl Message for Request {}
  #[derive(Clone, Debug, Default)]
  pub struct Response {}
  impl Message for Response {}
  
  pub struct OtherResponse {}
  pub enum ReplyError {
      InvalidData,
  }
  pub struct EventMessage {
      data: Vec&lt;u8&gt;,
  }
  
  pub struct Subscription {}
  
  impl Subscription {
      pub async fn next(&amp;self) -&gt; Option&lt;EventMessage&gt; {
          Some(EventMessage { data: vec![] })
      }
  }
  /// End external crates mocked here
  
  #[derive(Clone)]
  pub struct Publisher&lt;T&gt; {
      connection: Connection,
      subject: String,
      resource_type: PhantomData&lt;*const T&gt;,
  }
  
  #[derive(Debug)]
  pub enum PublishError {
      SerializeError(String),
      PublishError(String),
  }
  
  pub type PublishResult&lt;T&gt; = std::result::Result&lt;T, PublishError&gt;;
  
  impl&lt;T: Message&gt; Publisher&lt;T&gt; {
      pub fn new(connection: Connection, subject: String) -&gt; Self {
          let resource_type = PhantomData;
  
          Publisher {
              connection: connection,
              subject,
              resource_type,
          }
      }
      pub async fn publish(&amp;self, msg: T) -&gt; PublishResult&lt;()&gt;
      where
          T: Message,
      {
          // do stuff to msg
          Ok(())
      }
  }
  
  #[tokio::main]
  async fn main() -&gt; Result&lt;(), Box&lt;dyn std::error::Error&gt;&gt; {
      let node = Node::new(&quot;127.0.0.1&quot;, &quot;node&quot;.into())
          .await
          .expect(&quot;connecting to NATS&quot;);
      let p: Publisher&lt;Request&gt; = node.get_publisher(&quot;TOPIC&quot;.into());
      let _submission_replyer: AsynkReplyer&lt;Request, Response&gt; = node
          .get_replyer(&quot;request&quot;.into(), move |req: Arc&lt;Mutex&lt;Request&gt;&gt;| async {
              let mut req = req.clone().lock().unwrap();
              p.clone().publish(*req);
              Ok(Response {})
          })
          .await;
  
      Ok(())
  }
  
  pub struct Node {
      name: String,
      connection: Connection,
  }
  
  pub type ReplyResult&lt;T&gt; = std::result::Result&lt;T, ReplyError&gt;;
  
  impl Node {
      pub async fn new(_nats_url: &amp;str, name: String) -&gt; std::io::Result&lt;Self&gt; {
          env_logger::init();
  
          let connection = Connection {};
          Ok(Node { name, connection })
      }
  
      pub fn get_publisher&lt;T&gt;(&amp;self, subject: String) -&gt; Publisher&lt;T&gt;
      where
          T: Message + Default,
      {
          Publisher::new(self.connection.clone(), subject)
      }
  
      pub async fn get_replyer&lt;Req, Resp, Fut&gt;(
          &amp;self,
          subject: String,
          callback: impl Fn(Arc&lt;Mutex&lt;Req&gt;&gt;) -&gt; Fut + Send + Sync + 'static + Copy,
      ) -&gt; AsynkReplyer&lt;Req, Resp&gt;
      where
          Req: Message + Default + 'static,
          Resp: Message + Default,
          Fut: Future&lt;Output = ReplyResult&lt;Resp&gt;&gt; + Send,
      {
          AsynkReplyer::new(&amp;self.connection, subject, callback).await
      }
  }
  
  pub struct AsynkReplyer&lt;Req, Resp&gt; {
      request_type: PhantomData&lt;Req&gt;,
      response_type: PhantomData&lt;Resp&gt;,
  }
  
  impl&lt;Req: Message + Default + 'static, Resp: Message + Default&gt; AsynkReplyer&lt;Req, Resp&gt; {
      pub async fn new&lt;Fut&gt;(
          connection: &amp;Connection,
          subject: String,
          callback: impl Fn(Arc&lt;Mutex&lt;Req&gt;&gt;) -&gt; Fut + Send + Sync + 'static + Copy,
      ) -&gt; AsynkReplyer&lt;Req, Resp&gt;
      where
          Fut: Future&lt;Output = ReplyResult&lt;Resp&gt;&gt; + Send,
      {
          Self::start_subscription_handler(Subscription {}, callback).await;
  
          AsynkReplyer {
              request_type: PhantomData,
              response_type: PhantomData,
          }
      }
  
      pub async fn start_subscription_handler&lt;Fut&gt;(
          subscription: Subscription,
          callback: impl Fn(Arc&lt;Mutex&lt;Req&gt;&gt;) -&gt; Fut + Send + Sync + 'static + Copy,
      ) where
          Fut: Future&lt;Output = ReplyResult&lt;Resp&gt;&gt; + Send,
      {
          tokio::spawn(async move {
              loop {
                  match subscription.next().await {
                      Some(msg) =&gt; {
                          Self::handle_request(msg, callback).await;
                      }
                      None =&gt; {
                          break;
                      }
                  }
              }
          });
      }
  
      /// Decodes + spins up another task to handle the request
      pub async fn handle_request&lt;Fut&gt;(
          msg: EventMessage,
          callback: impl Fn(Arc&lt;Mutex&lt;Req&gt;&gt;) -&gt; Fut + Send + Sync + 'static + Copy,
      ) -&gt; ReplyResult&lt;()&gt;
      where
          Fut: Future&lt;Output = ReplyResult&lt;Resp&gt;&gt; + Send,
      {
          let decoded = Req::decode(msg.data.as_slice()).map_err(|_| ReplyError::InvalidData)?;
  
          tokio::spawn(async move {
              match callback(Arc::new(Mutex::new(decoded))).await {
                  Ok(response) =&gt; {
                      // do stuff
                  }
                  Err(e) =&gt; {}
              }
          });
          Ok(())
      }
  }
  </code></pre>
  <p>error:</p>
  <pre><code>error[E0277]: the trait bound `Publisher&lt;Request&gt;: std::marker::Copy` is not satisfied in `[closure@src/main.rs:93:40: 97:10]`
    --&gt; src/main.rs:93:10
     |
  93 |           .get_replyer(&quot;request&quot;.into(), move |req: Arc&lt;Mutex&lt;Request&gt;&gt;| async {
     |  __________^^^^^^^^^^^___________________-
     | |          |
     | |          within `[closure@src/main.rs:93:40: 97:10]`, the trait `std::marker::Copy` is not implemented for `Publisher&lt;Request&gt;`
  94 | |             let mut req = req.clone().lock().unwrap();
  95 | |             p.clone().publish(*req);
  96 | |             Ok(Response {})
  97 | |         })
     | |_________- within this `[closure@src/main.rs:93:40: 97:10]`
     |
     = note: required because it appears within the type `[closure@src/main.rs:93:40: 97:10]`
  
  error[E0277]: `*const Request` cannot be sent between threads safely
    --&gt; src/main.rs:93:10
     |
  93 |           .get_replyer(&quot;request&quot;.into(), move |req: Arc&lt;Mutex&lt;Request&gt;&gt;| async {
     |  __________^^^^^^^^^^^___________________-
     | |          |
     | |          `*const Request` cannot be sent between threads safely
  94 | |             let mut req = req.clone().lock().unwrap();
  95 | |             p.clone().publish(*req);
  96 | |             Ok(Response {})
  97 | |         })
     | |_________- within this `[closure@src/main.rs:93:40: 97:10]`
     |
     = help: within `[closure@src/main.rs:93:40: 97:10]`, the trait `Send` is not implemented for `*const Request`
     = note: required because it appears within the type `PhantomData&lt;*const Request&gt;`
  note: required because it appears within the type `Publisher&lt;Request&gt;`
    --&gt; src/main.rs:53:12
     |
  53 | pub struct Publisher&lt;T&gt; {
     |            ^^^^^^^^^
     = note: required because it appears within the type `[closure@src/main.rs:93:40: 97:10]`
  
  error[E0277]: `*const Request` cannot be shared between threads safely
    --&gt; src/main.rs:93:10
     |
  93 |           .get_replyer(&quot;request&quot;.into(), move |req: Arc&lt;Mutex&lt;Request&gt;&gt;| async {
     |  __________^^^^^^^^^^^___________________-
     | |          |
     | |          `*const Request` cannot be shared between threads safely
  94 | |             let mut req = req.clone().lock().unwrap();
  95 | |             p.clone().publish(*req);
  96 | |             Ok(Response {})
  97 | |         })
     | |_________- within this `[closure@src/main.rs:93:40: 97:10]`
     |
     = help: within `[closure@src/main.rs:93:40: 97:10]`, the trait `Sync` is not implemented for `*const Request`
     = note: required because it appears within the type `PhantomData&lt;*const Request&gt;`
  note: required because it appears within the type `Publisher&lt;Request&gt;`
    --&gt; src/main.rs:53:12
     |
  53 | pub struct Publisher&lt;T&gt; {
     |            ^^^^^^^^^
     = note: required because it appears within the type `[closure@src/main.rs:93:40: 97:10]`
  </code></pre>
  <p>I can't (or can I) add the <code>Copy</code> attribute on the <code>Publisher</code> struct but that wont work since not all of its fields implement <code>Copy</code>. Despite this I've commented out the fields in <code>Publisher</code> that don't impl <code>Copy</code> and added the attribute to it just to see, and with that approach I get:</p>
  <pre><code>the trait `std::marker::Copy` is not implemented for `Request`
  </code></pre>
  <p>Request is a <code>protobuf</code> based struct compiled using the prost lib. I'm not able to add the <code>Copy</code> attribute to that because of some of its fields not implementing <code>Copy</code> such as <code>String</code> and <code>Timestamp</code>.</p>
  <p>I'm wondering if the design here is just inherently bad or if there's a simple fix.</p>