title: Explicit type annotation for generic constructor of a generic type
body: <p>I'm writing a Rust binding for a C library. It implements an entity that can be constructed from different source entities, possibly saving some references internally. I want the Rust type to enforce a safe ownership policy, thus the wrapper struct is generic, parameterized by the type of the stored reference.</p>
  
  <pre><code>struct Foobar&lt;T&gt; {
      origin: T,
  }
  </code></pre>
  
  <p>Then I implement some constructors for my <code>Foobar</code> type.</p>
  
  <pre><code>impl&lt;T&gt; Foobar&lt;T&gt; {
      fn from_nowhere() -&gt; Foobar&lt;()&gt; {
          Foobar { origin: () }
      }
  
      fn from_orange&lt;F&gt;(orange: &amp;mut F) -&gt; Foobar&lt;&amp;mut F&gt;
          where F: Orange
      {
          Foobar { origin: orange }
      }
  
      fn from_callback&lt;F&gt;(callback: F) -&gt; Foobar&lt;F&gt;
          where F: FnMut(u64) -&gt; u64
      {
          Foobar { origin: callback }
      }
  }
  </code></pre>
  
  <p>And here comes the problem: both the struct and the constructor are independently parameterized. While the constructor type parameter can be inferred from its arguments, the struct type parameter is not used in the constructor and cannot be inferred. Thus, the naive way to call a constructor</p>
  
  <pre><code>let a = Foobar::from_nowhere();
  let b = Foobar::from_orange(&amp;mut fruit);
  let c = Foobar::from_callback(|x| x*x);
  </code></pre>
  
  <p>confuses rustc:</p>
  
  <pre><code>    rustgen.rs:43:13: 43:33 error: unable to infer enough type information about `_`; type annotations required [E0282]
      rustgen.rs:43     let a = Foobar::from_nowhere();
  </code></pre>
  
  <p>It can be fixed by providing some arbitrary type parameter:</p>
  
  <pre><code>let a = Foobar::&lt;()&gt;::from_nowhere();
  let b = Foobar::&lt;()&gt;::from_orange(&amp;mut fruit);
  let c = Foobar::&lt;()&gt;::from_callback(|x| x*x);
  </code></pre>
  
  <p>...which is all sorts of ugly. Another way to solve the problem would be to turn constructors into free functions, though it would be (kinda) non-idiomatic.</p>
  
  <p>The question is, am I missing something? The design seems to be flawed in some way. What would be the proper way to design this type to get away with only one level of generics?</p>
  
  <hr>
  
  <p><a href="http://is.gd/KeC7T2" rel="noreferrer">Minimal reproducible example on Rust playpen</a></p>
  
  <p>For reference, my compiler version is:</p>
  
  <pre><code>$ rustc --version
  rustc 1.1.0-dev (built 2015-04-26)
  </code></pre>