title: Difference between iter() and into_iter() on a shared, borrowed Vec?
body: <p>I am reading the <a href="https://www.ralfj.de/projects/rust-101/part04.html#section-5">Rust 101 tutorial</a>, where the author talks about shared borrowing with the example of a <code>Vec</code> object passed to a function. Below is a slightly adapted MWE of what the the tutorial is teaching. The interesting part is <code>v.iter()</code> in <code>vec_min</code>. The author writes:</p>
  
  <blockquote>
    <p>This time, we explicitly request an iterator for the vector <code>v</code>. The method <code>iter</code> borrows the vector it works on, and provides shared borrows of the elements.</p>
  </blockquote>
  
  <p>But what happens if I use a <code>for ... in ...</code> construction on an object which is shared? According to <a href="http://hermanradtke.com/2015/06/22/effectively-using-iterators-in-rust.html">this blog post</a>, this implicit for loop uses <code>into_iter()</code>, taking ownership of <code>v</code>. But it cannot really take ownership of the <code>v</code> in that function, since it has only borrowed it to begin with, right?</p>
  
  <p>Can somebody explain the difference between <code>into_iter()</code> and <code>iter()</code> applied to a borrowed object to me?</p>
  
  <pre><code>enum NumberOrNothing {
      Number(i32),
      Nothing,
  }
  use self::NumberOrNothing::{Number,Nothing};
  
  impl NumberOrNothing {
      fn print(self) {
          match self {
              Nothing =&gt; println!("The number is: &lt;nothing&gt;"),
              Number(n) =&gt; println!("The number is: {}", n),
          };
      }
  }
  
  fn vec_min(v: &amp;Vec&lt;i32&gt;) -&gt; NumberOrNothing {
      fn min_i32(a: i32, b: i32) -&gt; i32 {
          if a &lt; b {a} else {b}
      }
  
      let mut min = Nothing;
      for e in v.iter() {
      //Alternatively implicitly and with *e replaced by e:
      //for e in v {
          min = Number(match min {
              Nothing =&gt; *e,
              Number(n) =&gt; min_i32(n, *e),
          });
      }
      min
  }
  
  pub fn main() {
      let vec = vec![18,5,7,2,9,27];
      let foo = Nothing;
      let min = vec_min(&amp;vec);
      let min = vec_min(&amp;vec);
      min.print();
  }
  </code></pre>