title: How can I return a JoinHandle from a function?
body: <p>What is the best way to handle a situation like this:</p>
  
  <pre><code>use std::thread;
  
  struct Prefe;
  
  fn main() {
      let prefe = Prefe;
  
      start(&amp;prefe).join();
  }
  
  fn start(pre: &amp;Prefe) -&gt; thread::JoinHandle {
      thread::spawn(move || {
          println!("Test spawn");
      })
  }
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0243]: wrong number of type arguments: expected 1, found 0
    --&gt; src/main.rs:11:26
     |
  11 | fn start(pre: &amp;Prefe) -&gt; thread::JoinHandle {
     |                          ^^^^^^^^^^^^^^^^^^ expected 1 type argument
  </code></pre>
  
  <p>I think I could use something like this, but I do not know what to use for <code>T</code>:</p>
  
  <pre><code>fn start&lt;T&gt;(pre: &amp;Prefe, t: T) -&gt; thread::JoinHandle&lt;T&gt; {
      thread::spawn(move || {
          println!("Test spawn");
      })
  }
  </code></pre>
  
  <p>I see that <code>thread::spawn</code> uses this to return, but I do not know if this can help me or how to use it:</p>
  
  <pre><code>Builder::new().spawn(f).unwrap()
  </code></pre>
  
  <p>This seems to work, but I do not know if this is the right or wrong way:</p>
  
  <pre><code>fn start(pre: &amp;Prefe) -&gt; thread::JoinHandle&lt;()&gt; {
      thread::spawn(move || {
          println!("Test spawn");
      })
  }
  </code></pre>