title: What type is the "type ()" in Rust?
body: <p>As a simple exercise to learn Rust, I've decided to implement a simple binary search:</p>
  
  <pre><code>pub fn binary_search(arr: &amp;[i32], key: i32) -&gt; usize {
      let min: usize = 0;
      let max: usize = arr.len();
      while max &gt;= min {
          let mid: usize = (max - min) / 2 as usize;
          if key == arr[mid] {
              mid as usize
          }
  
          if key &lt; arr[mid] {
              min = mid + 1;
              continue;
          }
  
          max = mid - 1;
      }
      -1 as usize
  }
  
  #[cfg(test)]
  mod tests {
  
      use super::binary_search;
  
      #[test]
      fn binary_search_works() {
          let arr: [i32; 8] = [1, 2, 3, 4, 5, 6, 7, 8];
          let index: usize = binary_search(&amp;arr, 2);
          assert_eq!(1, index);
      }
  }
  </code></pre>
  
  <p>At build time, I get this error which I do not understand. What is the <code>()</code> type? Variable <code>mid</code> is always <code>usize</code> but even with the <code>as</code> cast I'm getting this compilation error.</p>
  
  <pre><code>error: mismatched types [E0308]
              mid as usize
              ^~~~~~~~~~~~
  help: run `rustc --explain E0308` to see a detailed explanation
  note: expected type `()`
  note:    found type `usize`
  </code></pre>