title: Creating a Generic Struct Indexed by a Generic NewType
body: <p>I'd like to create a generic struct that uses a generic newtype to index. Ideally it would look something like this:</p>
  <pre><code>use std::marker::PhantomData;
  
  struct Foo&lt;I, T&gt; {
      bar: Vec&lt;T&gt;,
      _marker: PhantomData&lt;I&gt;,
  }
  
  impl &lt;I, T&gt; Foo&lt;I, T&gt; {
      fn new(v: Vec&lt;T&gt;) -&gt; Foo&lt;I, T&gt; {
          Foo {
              bar: v,
              _marker: PhantomData,
          }
      }
      fn get(&amp;self, index: &amp;I) -&gt; &amp;T {
          // let index: usize = index.0; // I want to use this line.
          let index = 0; // This line is incorrect, but compiles.
          &amp;self.bar[index]
      }
  }
  </code></pre>
  <p>The generic newtype is guaranteed to be <code>usize</code>, like this:</p>
  <pre><code>pub struct Baz(pub usize);
  pub struct Qux(pub usize);
  </code></pre>
  <p>This compiles and correctly enforces type checking.</p>
  <pre><code>fn main() {
      let index_b = Baz(1);
      let index_q = Qux(1);
      let data: Foo&lt;Baz, i32&gt; = Foo::new(vec![1,2,3]);
      assert_eq!(*data.get(&amp;index_b), 2);
  
      // Type Checking Violation - Does not compile.
      // assert_eq!(*data.get(&amp;index_q), 2);
  }
  </code></pre>
  <p>However notice that the <code>get()</code> function is incorrect. How do you tell the compiler that <code>I</code> is a usize so the <code>get()</code> function will be correct?</p>