title: What is the correct way to get values via a method without moving it?
body: <p>I don't understand why Rust moves the value. Do I oversee a major point in the ownership?</p>
  
  <p>The struct <code>MyData</code> is a smaller version. I store some values in this struct, and want to access the stored values, but the compiler tells me after the second access, that the value was moved.</p>
  
  <p>I want to make some getters for my structs. I already derived <code>Clone</code>, but that does not help.</p>
  
  <p>The problem occurs on Windows 10 with the GNU-Compiler and on Kubuntu 18.04 LTS.</p>
  
  <p>My current workaround is to clone the data beforehand, but this can't be the correct way.</p>
  
  <pre><code>#[derive(Debug, Clone)]
  struct MyData {
      val1: i32,
      val2: String,
  }
  
  impl MyData {
      pub fn get_val1(self) -&gt; i32 {
          return self.val1.clone();
      }
  
      pub fn get_val2(self) -&gt; String {
          return self.val2.clone();
      }
  
      pub fn get_both(self) -&gt; (i32, String) {
          return (self.val1, self.val2);
      }
  }
  
  fn main() {
      let d = MyData {
          val1: 35,
          val2: String::from("Hello World"),
      };
  
      let both = d.get_both();
      let x = d.get_val1();
      let y = d.get_val2();
  }
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>error[E0382]: use of moved value: `d`
    --&gt; src/main.rs:28:13
     |
  27 |     let both = d.get_both();
     |                - value moved here
  28 |     let x = d.get_val1();
     |             ^ value used here after move
     |
     = note: move occurs because `d` has type `MyData`, which does not implement the `Copy` trait
  
  error[E0382]: use of moved value: `d`
    --&gt; src/main.rs:29:13
     |
  28 |     let x = d.get_val1();
     |             - value moved here
  29 |     let y = d.get_val2();
     |             ^ value used here after move
     |
     = note: move occurs because `d` has type `MyData`, which does not implement the `Copy` trait
  </code></pre>
  
  <p>I expect that <code>let x = d.get_val1();</code> won't cause an error. In my understanding of ownership in Rust, I did not move the value, since I'm calling a method of <code>MyData</code> and want to work with the value.</p>
  
  <p>Why does Rust move the value and to whom?</p>