Cannot pass self as callback parameter due to double borrowing

The simplest solution is to break the callback out from self, like so:

let callback = self.click_callback.take();
if let Some(ref mut c) = callback {
    c(self);
}
self.click_callback = callback;
self

This temporarily replaces click_callback with None, hence why you have to put it back when you’re done.

Leave a Comment