title: Calculate sum of chars in parallel
body: <p>I have an array of strings. I would like to count the total chars but using threads for parallelisation (the original problem is not this but is similar).</p>
  
  <pre class="lang-rust prettyprint-override"><code>use std::thread;
  
  pub fn frequency&lt;'a&gt;(input: &amp;'a [&amp;'a str], worker_count: usize) -&gt; usize {
      let handlers: Vec&lt;thread::JoinHandle&lt;usize&gt;&gt; = input
          .chunks(worker_count)
          .map(|chunk| thread::spawn(calculate(chunk)))
          .collect();
  
      let hashes = handlers.into_iter().map(|handler| handler.join().unwrap());
  
      let mut sum = 0;
      for h in hashes {
          sum += h
      }
  
      sum
  }
  
  fn calculate&lt;'a&gt;(input: &amp;'a [&amp;'a str]) -&gt; impl Fn() -&gt; usize + 'a {
      move || input.iter().map(|s| s.len()).sum()
  }
  </code></pre>
  
  <p>The compiler tells me this:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0495]: cannot infer an appropriate lifetime for autoref due to conflicting requirements
   --&gt; src/lib.rs:5:10
    |
  5 |         .chunks(worker_count)
    |          ^^^^^^
    |
  note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 3:18...
   --&gt; src/lib.rs:3:18
    |
  3 | pub fn frequency&lt;'a&gt;(input: &amp;'a [&amp;'a str], worker_count: usize) -&gt; usize {
    |                  ^^
  note: ...so that reference does not outlive borrowed content
   --&gt; src/lib.rs:4:52
    |
  4 |     let handlers: Vec&lt;thread::JoinHandle&lt;usize&gt;&gt; = input
    |                                                    ^^^^^
    = note: but, the lifetime must be valid for the static lifetime...
  note: ...so that the type `impl std::ops::Fn&lt;()&gt;` will meet its required lifetime bounds
   --&gt; src/lib.rs:6:22
    |
  6 |         .map(|chunk| thread::spawn(calculate(chunk)))
    |                      ^^^^^^^^^^^^^
  </code></pre>
  
  <p>I've tried to remove all lifetimes, use different lifetimes for <code>str</code> and the slice, and explicitly invoke <code>calculate::&lt;'a&gt;</code> but none of those solutions compile.</p>
  
  <p>The input lifetime is the same everywhere: <code>frequency</code> declares <code>'a</code> that is used in <code>calculate</code>, so the closure is bound to <code>'a</code> because the captured variables live for <code>'a</code>.</p>
  
  <p>Where am I wrong?</p>
  
  <p>NB: I would like not to use <code>'static</code>.</p>