Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Created July 11, 2025 22:43
Show Gist options
  • Save evanrelf/3734ebf5a89a69260689223f72589195 to your computer and use it in GitHub Desktop.
Save evanrelf/3734ebf5a89a69260689223f72589195 to your computer and use it in GitHub Desktop.
pub struct Defer<F: FnMut()>(F);
pub fn defer<F>(f: F) -> Defer<F>
where
F: FnMut(),
{
Defer(f)
}
impl<F> Drop for Defer<F>
where
F: FnMut(),
{
fn drop(&mut self) {
(self.0)();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment