title: What are move semantics in Rust?
body: <p>In Rust, there are two possibilities to take a reference</p>
  
  <ol>
  <li><p><strong>Borrow</strong>, i.e., take a reference but don't allow mutating the reference destination. The <code>&amp;</code> operator borrows ownership from a value.</p></li>
  <li><p><strong>Borrow mutably</strong>, i.e., take a reference to mutate the destination. The <code>&amp;mut</code> operator mutably borrows ownership from a value.</p></li>
  </ol>
  
  <p>The <a href="https://doc.rust-lang.org/book/first-edition/references-and-borrowing.html#the-rules" rel="noreferrer">Rust documentation about borrowing rules</a> says:</p>
  
  <blockquote>
    <p>First, any borrow must last for a scope no greater than that of the
    owner. Second, you may have one or the other of these two kinds of
    borrows, but not both at the same time:</p>
    
    <ul>
    <li>one or more references (<code>&amp;T</code>) to a resource,</li>
    <li>exactly one mutable reference (<code>&amp;mut T</code>).</li>
    </ul>
  </blockquote>
  
  <p>I believe that taking a reference is creating a pointer to the value and accessing the value by the pointer. This could be optimized away by the compiler if there is a simpler equivalent implementation.</p>
  
  <p>However, I don't understand what <strong>move</strong> means and how it is implemented.</p>
  
  <p>For types implementing the <code>Copy</code> trait it means copying e.g. by assigning the struct member-wise from the source, or a <code>memcpy()</code>. For small structs or for primitives this copy is efficient.</p>
  
  <p>And for <strong>move</strong>?</p>
  
  <p>This question is not a duplicate of <a href="https://stackoverflow.com/q/3106110/220060">What are move semantics?</a> because Rust and C++ are different languages and move semantics are different between the two.</p>