title: How do I shift the elements inside a Rust vector to the right and put the out-of-bounds element at the beginning?
body: <p>I am trying to move the elements in a vector to the right and then place the out of bounds element back at the beginning; a rotation of the vector. </p>
  
  <p>This is pseudocode to move the first element in the vector 1 step. Since the vector is only 5 elements, the <code>5</code> goes back to the start of the vector:</p>
  
  <pre><code>let V = vec![1, 2, 3, 4, 5];
  A = V.move[0].cycle();
  A = [5, 1, 2, 3, 4];
  </code></pre>
  
  <p>The <code>A = V.move[0].cycle();</code> is my attempt at this, but since Rust doesn't rotate if the index is out of bounds, it can be hard to implement. </p>
  
  <p>In Python, it's possible to use the <code>pop</code> function with lists:</p>
  
  <pre class="lang-none prettyprint-override"><code>&gt;&gt;&gt;m = [1, 2, 3, 4, 5]
  &gt;&gt;&gt;m += [m.pop(0)]
  &gt;&gt;&gt;m
  [2, 3, 4, 5, 1]
  </code></pre>
  
  <p>Using a for loop, it's possible to shift all elements to be <code>[5, 1, 2, 3, 4]</code>. Is there an equivalent to the <code>pop</code> function in Rust? 
  It would even be better if there is a function to shift elements all together.</p>