mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-22 15:21:04 +00:00
13 lines
232 B
Rust
13 lines
232 B
Rust
pub struct Defer<F: FnOnce()>(Option<F>);
|
|
|
|
impl<F: FnOnce()> Defer<F> {
|
|
pub fn new(f: F) -> Self { Defer(Some(f)) }
|
|
}
|
|
|
|
impl<F: FnOnce()> Drop for Defer<F> {
|
|
fn drop(&mut self) {
|
|
if let Some(f) = self.0.take() {
|
|
f();
|
|
}
|
|
}
|
|
}
|