Iterating over a slice's values instead of references in Rust?
<p>When looping over a slice of structs, the value I get is a reference (which is fine), however in some cases it's annoying to have to write <code>var</code> as <code>(*var)</code> in many places.</p>

<p>Is there a better way to avoid re-declaring the variable?</p>

<pre><code>fn my_fn(slice: &amp;[MyStruct]) {
    for var in slice {
        let var = *var;  // &lt;-- how to avoid this?

        // Without the line above, errors in comments occur:

        other_fn(var);  // &lt;-- expected struct `MyStruct`, found reference

        if var != var.other {
            // ^^ trait `&amp;MyStruct: std::cmp::PartialEq&lt;MyStruct&gt;&gt;` not satisfied
            foo();
        }
    }
}
</code></pre>

<hr>

<p>See: <a href="https://bitbucket.org/snippets/ideasman42/eeepa" rel="noreferrer">actual error output</a> (more cryptic).</p>