title: Rust Constraints for Generic Type Reference
body: <p>Here's the scenario: I have a structure and trait pair as follows:</p>
  
  <pre><code>trait Operation {
      fn operation(self) -&gt; u32
  }
  
  struct Container&lt;T: Sized + Operation&gt; {
      x:T
  }
  
  impl &lt;T: Sized + Operation&gt; for Container&lt;T&gt; {
      fn do_thing(&amp;self) -&gt; u32 {
          // Do something with the field x.
      }
  }
  </code></pre>
  
  <p>The operation requires a pass-by-value call whenever used, and the issue comes with anything similar to "do_thing." I would prefer to not have to enforce copy semantics for the type <code>T</code> and would like a workaround for this. Essentially I would like to know the following:</p>
  
  <ol>
  <li>Is it possible to enforce trait constraints on references of type parameters? Something along the lines of: <code>struct Container&lt;T: Sized + Operation&gt; where &amp;T: Operation { ... }</code>. I've tried mucking with the syntax a bit, and I've not had any success.</li>
  <li>If the above is not currently possible, is it theoretically possible; i.e. it doesn't violate any require coherence properties or something along those lines?</li>
  <li>Would it be possible to create a second trait, say <code>Middle: Operation</code>, where <code>Middle</code> can require that any implementers of <code>Middle</code>, <code>T</code>, to also be required to implement <code>Operation</code> for <code>&amp;T</code>.</li>
  <li>If neither of the above are possible, is there some other common workaround for this?</li>
  </ol>
  
  <p>Some Notes:</p>
  
  <ul>
  <li>I don't have access to change the <code>Operation</code> trait, it's given and it's what I'm to work with.</li>
  <li>There's an <a href="https://github.com/rust-lang/rfcs/blob/master/text/0135-where.md" rel="noreferrer">old RFC</a> that talks about some modifications to where clauses, but I didn't find anything related to reference constraints.</li>
  <li>compiler version: <em>rustc 1.8.0 (db2939409 2016-04-11)</em></li>
  </ul>