title: still trying to reimplement a c++ timerqueue in rust
body: <p><a href="https://stackoverflow.com/questions/63094917/more-on-reimplementing-c-timerqueue-in-rust">more on reimplementing c++ timerqueue in rust</a></p>
  <p>This code tries to create a vec of tasks and run them on a different thread. Still cannot compile it. I am at the point of typing words at random into random locations to see if it helps , 'static here, move there dyn sync ,....</p>
  <p>I think if I were to see a working version I would be able to work out why I was stuck. But I cannot make it go.</p>
  <p>heres the complete code</p>
  <pre><code>use std::thread;
  use std::time::Instant;
  
  fn main() {
      let x = || {
          println!(&quot;hello&quot;);
      };
      let y = || {
          println!(&quot;hello2&quot;);
      };
  
      let mut tq = TimerQueue::new();
      tq.set(Box::new(x), String::from(&quot;yo&quot;), Instant::now());
      tq.set(Box::new(y), String::from(&quot;yo&quot;), Instant::now());
      tq.thr();
  }
  
  pub struct TimerQueueItem {
      when: Instant,
      name: String,
      what: QIFunc,
  }
  type QIFunc = Box&lt;dyn Fn() -&gt; () + Send&gt;;
  
  struct TimerQueue {
      queue: Vec&lt;TimerQueueItem&gt;,
  }
  
  impl TimerQueue {
      fn thr(&amp;mut self) -&gt; () {
          thread::spawn(move || {
              self.runq();
          });
      }
  
      fn set(&amp;mut self, f: QIFunc, n: String, when: Instant) {
          let qi = TimerQueueItem {
              what: f,
              name: n,
              when: when,
          };
          self.queue.push(qi);
      }
      fn new() -&gt; TimerQueue {
          TimerQueue { queue: Vec::new() }
      }
      fn runq(&amp;mut self) -&gt; () {
          for qi in self.queue.iter() {
              (qi.what)();
          }
      }
  }
  </code></pre>
  <p>all sorts of errors all pointing at the same place</p>
  <pre><code>error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
    --&gt; src\main.rs:31:23
     |
  31 |           thread::spawn(move || {
     |  _______________________^
  32 | |             self.runq();
  33 | |         });
     | |_________^
     |
  note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 30:5...
    --&gt; src\main.rs:30:5
  </code></pre>
  <p>this one seems particularly designed to confuse</p>
  <pre><code>   = note: expected `&amp;mut TimerQueue`
                found `&amp;mut TimerQueue`
  </code></pre>