title: Idiomatic callbacks in Rust
body: <p>In C/C++ I'd normally do callbacks with a plain function pointer, maybe passing a <code>void* userdata</code> parameter too. Something like this:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>typedef void (*Callback)();
  
  class Processor
  {
  public:
      void setCallback(Callback c)
      {
          mCallback = c;
      }
  
      void processEvents()
      {
          for (...)
          {
              ...
              mCallback();
          }
      }
  private:
      Callback mCallback;
  };
  </code></pre>
  
  <p>What is the idiomatic way of doing this in Rust? Specifically, what types should my <code>setCallback()</code> function take, and what type should <code>mCallback</code> be? Should it take an <code>Fn</code>? Maybe <code>FnMut</code>? Do I save it <code>Boxed</code>? An example would be amazing.</p>