title: What goes on the stack and what goes on the heap in Rust?
body: <p>I am really confused about Rust's system of memory allocation.</p>
  <p>In Java you use <code>new</code> to allocate memory on the heap. In C you use <code>malloc()</code>, everything else goes on the stack.</p>
  <p>I thought, in Rust, <code>Box&lt;T&gt;</code> allocates memory on the heap but after reading <a href="https://doc.rust-lang.org/book/ch15-02-deref.html#defining-our-own-smart-pointer" rel="noreferrer">&quot;Defining Our Own Smart Pointer&quot; section in chapter 15.2 in <em>The Rust Programming Language</em></a> it seems like <code>MyBox&lt;T&gt;</code> doesn't have any special annotation to make the value of <code>T</code> live on the heap.</p>
  <ol>
  <li><p>What exactly goes on the stack and what goes on the heap?</p>
  </li>
  <li><p>Is the implementation of <code>MyBox&lt;T&gt;</code> essentially the same as <code>Box&lt;T&gt;</code>?</p>
  </li>
  <li><p>If the implementations are identical, what makes <code>T</code> stored on the heap rather than the stack?</p>
  </li>
  <li><p>If the implementations aren't identical what makes a <code>Box&lt;T&gt;</code> allocate memory on the heap?</p>
  </li>
  </ol>