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