How do I use a paremeter to index an array in rust? : <p>I'm trying to create a function that will take a parameter and use it as an index for an array rust will not let me do this and because of this I'm hoping to find an alternative method to achieve the same results.</p>

<p>although I'm not a 100% I believe that rust is not letting me run the code because it believes that the parameter I'm using might go beyond the lens of the array and for this I tried using the <code>get()</code> function:</p>

<pre class="lang-rust prettyprint-override"><code>array.get(foo).unwrap();
</code></pre>

<p>however this still doesn't fix my current error.</p>

<p>Sample code to reproduce error:</p>

<pre class="lang-rust prettyprint-override"><code>fn example(foo: u32) {
    let mut array: [u32; 3] = [0,0,0];    
    array[foo] = 9;
}
fn main() {
    example(1);
}
</code></pre>

<p>The program fails to run with the complier giving me the error</p>

<pre><code>array[foo] = 9
^^^^^^^^^^^^^^ slice indices are of type `usize` or ranges of `usize`
</code></pre>

<p>This is my first time writing a problem on stack overflow so if i messed the formatting somewhere, sorry.</p>
