title: What are the differences between using * and & to compare values for equality?
body: <p>I think I understand, at a very high level what the difference between <code>&amp;</code> and <code>*</code> in Rust is as it pertains to memory management.  </p>
  
  <p>What is the difference between the following code snippets.  Are there dangers to applying one approach versus the other?</p>
  
  <pre><code>for (i, item) in bytes.iter().enumerate() {
      if *item == b' ' {
          return i;
      }
  }
  </code></pre>
  
  
  
  <pre><code>for (i, &amp;item) in bytes.iter().enumerate() {
      if item == b' ' {
          return i;
      }
  }
  </code></pre>
  
  
  
  <pre><code>for (i, item) in bytes.iter().enumerate() {
      if item == &amp;b' ' {
          return i;
      }
  }
  </code></pre>
  
  <p>As I understand it, when I return a value from <code>iter()</code> I am returning a reference to the element found in <code>bytes</code>. If I want to make a comparison on the item, I need to either compare between two references <code>&amp;u8</code> or I need to make <code>&amp;item</code> a reference itself so that when I call <code>item</code> it is of type <code>u8</code>, or I need to dereference <code>item</code> when I compare it so that <code>item</code> = <code>&amp;u8</code> -> <code>*item</code> = <code>u8</code>.</p>
  
  <ol>
  <li><p>When I run the code using <code>(i, &amp;item)</code>, when I call <code>item</code> later on, is this exactly the same thing as dereferencing in the second example, or is there a fundamental difference about how the compiler is interpreting the first code snippet and the second code snippet?</p></li>
  <li><p>Is there anything wrong with the third code snippet? I realize this is a bit of an opinion based question.  I realize that if I were to assign a value to another variable using <code>item</code> (or <code>*item</code>, or assigning the value as a reference) I would have different datatypes being returned later on.  Aside from managing your data types, is there anything else to keep in mind when considering if <code>item == &amp;b' '</code> is the right tool for the job?</p></li>
  </ol>