Skip to content

Refactored some closures to use clone! macro.

Jordan Petridis requested to merge (removed):master into master

I am not really sure it was worth it or if it's even worth merging. I though the code would be more clonable but turns out most of the objects you would want to pass in a closure are derived from self. So you would either have to clone self which sound expensive or do the following:

let op = &self.op;
window.connect_delete_event(clone!(op => move |_, _| {
    op.lock().unwrap().quit();
    Inhibit(false)
}));

as opposed to:

let op = self.op.clone();
window.connect_delete_event(move |_, _| {
    op.lock().unwrap().quit();
    Inhibit(false)
});

Which turns out to be the same amount of boilerplate and not making any more readable, if anything else it would make it more complicated for people not familiar with the macro to understand.

Edited by Jordan Petridis

Merge request reports