title: Possible to define generic closure?
body: <p>Does Rust support closures with generic return types? For example, I want to write something like this:</p>
  
  <pre><code>let get&lt;T: FromValue&gt; = |s: &amp;str| -&gt; Option&lt;T&gt; { ... }
  </code></pre>
  
  <p>But that syntax is clearly wrong.</p>
  
  <p><strong>What I'm trying to do</strong></p>
  
  <p>I'm working with <a href="https://github.com/blackbeam/rust-mysql-simple" rel="noreferrer">rust-mysql-simple</a>, and I'm writing a <code>from_row</code> method for my <code>User</code> struct, to build a user from a database row.</p>
  
  <p>The library doesn't provide (as far as I can tell) a way to look up query result row values by column name. So to work around this, my method looks like (this compiles and works correctly):</p>
  
  <pre><code>fn from_row(result: &amp;QueryResult, row: Vec&lt;Value&gt;) -&gt; User {
  
      let mut map: HashMap&lt;_, _&gt; = row.into_iter().enumerate().collect();
  
      let mut get = |s: &amp;str|  {
          result.column_index(s)
             .and_then(|i| map.remove(&amp;i) )
      };
  
      User {
          id: get("id").and_then(|x| from_value_opt(x).ok() )
      }
  }
  </code></pre>
  
  <p>Here, <code>result</code> is an object that contains information about the query's column names (used to find the column index for a column name), and the <code>row</code> contains the ordered values from a query result row. <code>from_value_opt</code> is a method provided by the library that takes a <code>Value</code> and returns a <code>Result&lt;T, MyError&gt;</code>. The value is coerced to the field's type.</p>
  
  <p>I was trying to move the <code>.and_then(|x| from_value_opt(x).ok() )</code> into the <code>get</code> closure just to clean up the code some. However, when I do so, the closure return type is interpreted to be the result of the first occurrence of the <code>get</code> call.</p>
  
  <p>I rewrote the closure as a nested method that looks like:</p>
  
  <pre><code>fn get&lt;T: FromValue&gt;(r: &amp;QueryResult, m: &amp;mut HashMap&lt;usize, Value&gt;, s: &amp;str)
      -&gt; Option&lt;T&gt; { ... }
  </code></pre>
  
  <p>which also worked fine, but didn't help cutting the verbosity much.</p>