title: Cannot move out of borrowed content in Rust
body: <pre><code>pub struct Character {
      name: String,
      hp: i32,
      level: i32,
      xp: i32,
      xp_needed: i32,
      gold: i32
  }
  
  impl Character {
      pub fn new(name: String) -&gt; Character {
          let mut rng = thread_rng();
  
          let hp: i32 = rng.gen_range(12, 75);
          let gold: i32 = rng.gen_range(10, 50);
  
          Character { name: name, hp: hp, level: 1, xp: 0, gold: gold, xp_needed: 100 }
      }
  
      pub fn get_name(&amp;self) -&gt; String {
          self.name
      }
  
      // ...
  }
  </code></pre>
  
  <p>How exactly am I breaking the rules here?</p>
  
  <blockquote>
    <p>At a high-level, this is against-the-grain for Rust. You cannot transfer ownership of something borrowed because you don't own it.</p>
  </blockquote>
  
  <p>Um don't I? I have other functions like:</p>
  
  <pre><code>pub fn get_hp(&amp;self) -&gt; i32 {
      self.hp
  }
  </code></pre>
  
  <p>And that works just fine.</p>
  
  <pre class="lang-none prettyprint-override"><code>   |
  23 |         self.name
     |         ^^^^ cannot move out of borrowed content
  
  error: aborting due to previous error
  </code></pre>
  
  <p>What's going on? What is the appropriate approach to return the character name? Why does the <code>get_hp</code> method work but not <code>get_name</code>?</p>