Closures as a type in a Rust struct
<p>I am trying to create a struct like this in Rust:</p>

<pre><code>pub struct Struct&lt;T, F&gt;
    where T: Eq,
          T: Hash,
          F: Fn() -&gt; T
{
    hashMap: HashMap&lt;T, F&gt;,
    value: T,
}
</code></pre>

<p>My constructor looks like this:</p>

<pre><code>pub fn new(init_value: T) -&gt; Struct&lt;T, F&gt; {
    Struct {
        hashMap: HashMap::new(),
        value: init_state,
    }
}
</code></pre>

<p>However when trying to instantiate the class, using <code>let a = Struct::&lt;MyEnum&gt;::new(MyEnum::Init);</code>, the compiler complains that the generics needs two arguments (<code>expected 2 type arguments, found 1</code>)</p>

<p>I saw <a href="https://doc.rust-lang.org/book/closures.html" rel="noreferrer">here</a> that this code works:</p>

<pre><code>fn call_with_one&lt;F&gt;(some_closure: F) -&gt; i32
    where F: Fn(i32) -&gt; i32 {

    some_closure(1)
}

let answer = call_with_one(|x| x + 2);
</code></pre>

<p>I guess the problem comes from me having another generic in my template instantiation, but how can I do that?</p>