title: What is the idiomatic way to get the index of a maximum or minimum floating point value in a slice or Vec in Rust?
body: <p><strong>Assumption</strong> -- The <code>Vec&lt;f32&gt;</code> does <strong>not</strong> have any <code>NaN</code> values or exhibit any <code>NaN</code> behavior.</p>
  
  <p>Take the following sample set:</p>
  
  <pre class="lang-none prettyprint-override"><code>0.28  
  0.3102
  0.9856
  0.3679
  0.3697
  0.46  
  0.4311
  0.9781
  0.9891
  0.5052
  0.9173
  0.932 
  0.8365
  0.5822
  0.9981
  0.9977
  </code></pre>
  
  <p>What is the neatest and most stable way to get the <strong>index</strong> of the highest value in the above list (values can be negative)? </p>
  
  <p>My initial attempts were along the following lines:</p>
  
  <pre><code>let _tmp = *nets.iter().max_by(|i, j| i.partial_cmp(j).unwrap()).unwrap();    
  let _i = nets.iter().position(|&amp;element| element == _tmp).unwrap();
  </code></pre>
  
  <p>Where <code>nets</code> is a <code>&amp;Vec&lt;f32&gt;</code>. Which to me seems blatantly incorrect.</p>
  
  <p>The Python equivalent of this that works (taking into consideration the above assumption):</p>
  
  <pre class="lang-py prettyprint-override"><code>_i = nets.index(max(nets))
  </code></pre>