title: In Rust, how can I restrict a generic T to allow modulus?
body: <p>As an <a href="https://exercism.org/tracks/rust/exercises/low-power-embedded-game" rel="noreferrer">exercism exercise</a>, I'm currently trying to filter an iterator according to whether the value is even in order to produce a new iterator.</p>
  <p>My function currently looks like:</p>
  <pre><code>pub fn evens&lt;T&gt;(iter: impl Iterator&lt;Item = T&gt;) -&gt; impl Iterator&lt;Item = T&gt;
      where T: std::ops::Rem&lt;Output = T&gt;
  {
      iter.filter(|x| x % 2 != 0)
  }
  </code></pre>
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=8d8c99af164b7c584f0a809ea6ac26e2" rel="noreferrer">Playground</a></p>
  <p>But this won't compile because:</p>
  <pre class="lang-none prettyprint-override"><code>error[E0369]: cannot mod `&amp;T` by `{integer}`
   --&gt; src/lib.rs:4:23
    |
  4 |     iter.filter(|x| x % 2 != 0)
    |                     - ^ - {integer}
    |                     |
    |                     &amp;T
    |
  help: consider further restricting this bound
    |
  2 |     where T: std::ops::Rem&lt;Output = T&gt; + std::ops::Rem&lt;Output = {integer}&gt;
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  </code></pre>
  <p>However, I know I can't simply change this to</p>
  <pre class="lang-rust prettyprint-override"><code>pub fn evens&lt;T&gt;(iter: impl Iterator&lt;Item = T&gt;) -&gt; impl Iterator&lt;Item = T&gt;
      where T: std::ops::Rem&lt;Output = T&gt; + std::ops::Rem&lt;Output = {integer}&gt;
  {
      iter.filter(|x| x % 2 != 0)
  }
  </code></pre>
  <p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=6910374a2b3f1d08066b5043997b2fb4" rel="noreferrer">Playground</a></p>
  <p>as this fails to compile with:</p>
  <pre class="lang-none prettyprint-override"><code>error: cannot constrain an associated constant to a value
   --&gt; src/lib.rs:2:56
    |
  2 |     where T: std::ops::Rem&lt;Output = T&gt; + std::ops::Rem&lt;Output = {integer}&gt;
    |                                                        ------^^^---------
    |                                                        |        |
    |                                                        |        ...cannot be constrained to this value
    |                                                        this associated constant...
  </code></pre>
  <p>I'm vaguely aware of some &quot;Num&quot; traits, but the exercism doesn't seem to accept answers which require importing dependencies through Cargo.toml, so I'm looking for a native/built-in solution.</p>
  <p>Any ideas how I can make this work?</p>
  <p>(P.S. I've now figured out that I misunderstood the exercise, where &quot;even&quot; describes the enumerated index, not the value... but never mind.  I'd still like to know whether/how this could be made to work.)</p>