title: Is it possible to share data with threads without any cloning?
body: <p>When I'm delegating work to threads I often have a piece of data that will outlive all of the threads, such as <code>numbers</code> in the following example:</p>
  
  <pre><code>use std::thread;
  
  fn main() {
      let numbers = vec![1, 2, 3];
  
      let thread_a = thread::spawn(|| println!("{}", numbers.len()));
      let thread_b = thread::spawn(|| println!("{}", numbers.len()));
  
      thread_a.join().unwrap();
      thread_b.join().unwrap();
  }
  </code></pre>
  
  <p>It's not modified anywhere, and because of the <code>join</code>s, it's guaranteed that the threads are done using it. However, Rust's borrow checker is not able to tell:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0373]: closure may outlive the current function, but it borrows `numbers`, which is owned by the current function
   --&gt; src/main.rs:6:34
    |
  6 |     let thread_a = thread::spawn(|| println!("{}", numbers.len()));
    |                                  ^^                ------- `numbers` is borrowed here
    |                                  |
    |                                  may outlive borrowed value `numbers`
    |
  note: function requires argument type to outlive `'static`
   --&gt; src/main.rs:6:20
    |
  6 |     let thread_a = thread::spawn(|| println!("{}", numbers.len()));
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: to force the closure to take ownership of `numbers` (and any other referenced variables), use the `move` keyword
    |
  6 |     let thread_a = thread::spawn(move || println!("{}", numbers.len()));
    |                                  ^^^^^^^
  </code></pre>
  
  <p>The solutions I've seen so far all involve cloning the piece of data (or cloning an <code>Arc</code> of the data). Is it possible to do it without any cloning, though?</p>