title: Rust Derive Clone For a Specific Struct
body: <p><strong>Note:</strong> I am using <a href="https://github.com/hecrj/iced" rel="nofollow noreferrer">iced</a> for the GUI <code>TextInput</code> and <a href="https://github.com/tokio-rs/tokio" rel="nofollow noreferrer">tokio</a> for the networking <code>TcpStream</code></p>
  <p>I have the following:</p>
  <pre><code>#[derive(Debug, Clone)]
  enum Message {
      Session(Result&lt;Connection, ConnectionError&gt;), //Async Handler
      SendMessage,
      Send(Result&lt;Connection, ConnectionError&gt;), //Async Handler
      InputChanged(String),
      Button(usize, ButtonMessage),
      None,
  }
  
  #[derive(Debug)]
  enum ConnectionError {
      ConnectError(usize),
      SendError(usize),
  }
  
  #[derive(Debug)]
  struct Connection {
      stream: TcpStream,
      loc: usize,
  }
  </code></pre>
  <p>Problem is that my <code>Connection</code> struct contains a <code>TcpStream</code> that cannot be cloned (it wouldn't logistically make sense for it to be cloned anyway).</p>
  <p>So I get the error...</p>
  <pre><code>&gt;the trait bound `Connection: Clone` is not satisfied
    --&gt; src\main.rs:27:10
     |
  27 |     Session(Result&lt;Connection, ConnectionError&gt;), //Async Handler
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
     |
     = note: required because of the requirements on the impl of `Clone` for `std::result::Result&lt;Connection, ConnectionError&gt;`
     = note: required by `clone`
     = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
  
  &gt;error[E0277]: the trait bound `ConnectionError: Clone` is not satisfied
    --&gt; src\main.rs:27:10
     |
  27 |     Session(Result&lt;Connection, ConnectionError&gt;), //Async Handler
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
     |
     = note: required because of the requirements on the impl of `Clone` for `std::result::Result&lt;Connection, ConnectionError&gt;`
     = note: required by `clone`
     = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
  
  &gt;error[E0277]: the trait bound `Connection: Clone` is not satisfied
    --&gt; src\main.rs:29:7
     |
  29 |     Send(Result&lt;Connection, ConnectionError&gt;), //Async Handler
     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
     |
     = note: required because of the requirements on the impl of `Clone` for `std::result::Result&lt;Connection, ConnectionError&gt;`
     = note: required by `clone`
     = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
  
  &gt;error[E0277]: the trait bound `ConnectionError: Clone` is not satisfied
    --&gt; src\main.rs:29:7
     |
  29 |     Send(Result&lt;Connection, ConnectionError&gt;), //Async Handler
     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an implementor of trait `Clone`
     |
     = note: required because of the requirements on the impl of `Clone` for `std::result::Result&lt;Connection, ConnectionError&gt;`
     = note: required by `clone`
     = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
  </code></pre>
  <p>So I removed the Clone</p>
  <pre><code>#[derive(Debug)]
  enum Message {
      Session(Result&lt;Connection, ConnectionError&gt;), //Async Handler
      SendMessage,
      Send(Result&lt;Connection, ConnectionError&gt;), //Async Handler
      InputChanged(String),
      Button(usize, ButtonMessage),
      None,
  }
  </code></pre>
  <p>and get the following errors:</p>
  <pre><code>&gt;the trait bound `Message: Clone` is not satisfied
     --&gt; src\main.rs:516:15
      |
  516 |         let input = TextInput::new(
      |                     ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Message`
      |
     ::: C:\Users\bratl\.cargo\registry\src\github.com-1ecc6299db9ec823\iced_native-0.3.0\src\widget\text_input.rs:84:22
      |
  84  |         F: 'static + Fn(String) -&gt; Message,
      |                      --------------------- required by this bound in `iced_native::widget::text_input::TextInput::&lt;'a, Message, Renderer&gt;::new`
  
  &gt;error[E0599]: no method named `padding` found for struct `iced_native::widget::text_input::TextInput&lt;'_, Message, iced_graphics::renderer::Renderer&lt;iced_wgpu::backend::Backend&gt;&gt;` in the current scope
     --&gt; src\main.rs:522:4
      |
  26  | enum Message {
      | ------------ doesn't satisfy `Message: Clone`
  ...
  522 |         .padding(15)
      |          ^^^^^^^ private field, not a method
      |
      = note: the method `padding` exists but the following trait bounds were not satisfied:
              `Message: Clone`
  </code></pre>
  <p>So I went to where the <code>TextInput</code> was located and removed the <code>Clone</code> as well.</p>
  <pre><code>#[derive(Debug)]
  struct ClientAdminChatPaneContent {
      scroll: scrollable::State,
      input: text_input::State,
      input_value: String,
  }
  
  
  #[derive(Debug)]
  enum ChatPaneMessage {
      InputChanged(String),
  }
  
  impl ClientAdminChatPaneContent {
      fn new() -&gt; Self {
          ClientAdminChatPaneContent { 
              scroll: scrollable::State::new(),
              input: text_input::State::new(),
              input_value: String::from(&quot;&quot;),
          }
      }
  
      fn update(&amp;mut self, message: ChatPaneMessage) {
          match message {
              ChatPaneMessage::InputChanged(value) =&gt; {
                  //println!(&quot;Input Changed: {}&quot;, value);
                  self.input_value = value;
              }
          }
      }
  
      fn view(&amp;mut self) -&gt; Element&lt;Message&gt; {
  
          //Text Input
          let input = TextInput::new(
              &amp;mut self.input,
              &quot;Message to Client&quot;,
              &amp;self.input_value,
              Message::InputChanged,
          )
          .padding(15)    
          .size(30)
          .on_submit(Message::SendMessage);
          
          let text_input_container:Container&lt;Message&gt; = Container::new(input)
              .width(Length::Fill)
              .height(Length::Units(80))
              .padding(10);
  
          let scroll = Scrollable::new(&amp;mut self.scroll)
              .width(Length::Fill)
              .spacing(10)
              .align_items(Align::Start);
  
          let scroll_container:Container&lt;Message&gt; = Container::new(scroll)
              .width(Length::Fill)
              .height(Length::Fill)
              .padding(10);
  
          let mut content = Column::new()
              .spacing(5);
  
          content = content.push(scroll_container);
          content = content.push(text_input_container);
  
          Container::new(content)
              .width(Length::Fill)
              .height(Length::Fill)
              .padding(5)
              .center_y()
              .into()
      }
  
      fn clear_text(&amp;mut self) {
          self.input_value = String::from(&quot;&quot;);
      }
  }
  </code></pre>
  <p>And I get a new error:</p>
  <pre><code>&gt;the trait bound `Message: Clone` is not satisfied
     --&gt; src\main.rs:516:15
      |
  516 |         let input = TextInput::new(
      |                     ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Message`
      |
     ::: C:\Users\bratl\.cargo\registry\src\github.com-1ecc6299db9ec823\iced_native-0.3.0\src\widget\text_input.rs:84:22
      |
  84  |         F: 'static + Fn(String) -&gt; Message,
      |                      --------------------- required by this bound in `iced_native::widget::text_input::TextInput::&lt;'a, Message, Renderer&gt;::new`
  </code></pre>
  <p>As to why, I'm not sure why <code>let input = TextInput::new(</code> needs to implement <code>Clone</code>. But, assuming I need this struct to implement Clone, WITHOUT <code>Message</code> implementing Clone due to the TCP...</p>
  <p><strong>How do I get clone for a specific item, such as a <code>TextInput</code> without deriving it for every single item</strong> Or <em>Is this an entirely different issue</em>?</p>