aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx
diff options
context:
space:
mode:
Diffstat (limited to 'crates/stdx')
-rw-r--r--crates/stdx/src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index e3eb10915..857567a85 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -179,6 +179,18 @@ where
179 start..start + len 179 start..start + len
180} 180}
181 181
182pub fn defer<F: FnOnce()>(f: F) -> impl Drop {
183 struct D<F: FnOnce()>(Option<F>);
184 impl<F: FnOnce()> Drop for D<F> {
185 fn drop(&mut self) {
186 if let Some(f) = self.0.take() {
187 f()
188 }
189 }
190 }
191 D(Some(f))
192}
193
182#[repr(transparent)] 194#[repr(transparent)]
183pub struct JodChild(pub std::process::Child); 195pub struct JodChild(pub std::process::Child);
184 196