Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Last active November 2, 2025 19:24
Show Gist options
  • Select an option

  • Save evanrelf/3734ebf5a89a69260689223f72589195 to your computer and use it in GitHub Desktop.

Select an option

Save evanrelf/3734ebf5a89a69260689223f72589195 to your computer and use it in GitHub Desktop.
macro_rules! defer {
($f:expr) => {
let __defer = {
struct Defer<F: FnMut()>(F);
impl<F: FnMut()> Drop for Defer<F> {
fn drop(&mut self) {
(self.0)();
}
}
Defer($f)
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment