From cdfe5a8be01dd7427db734f17c5ec0de7bbe6c80 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 20 Apr 2021 22:54:05 +0300 Subject: fix: no more Registering progress handler for token rustAnalyzer/Indexing failed. --- crates/stdx/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/stdx') 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 start..start + len } +pub fn defer(f: F) -> impl Drop { + struct D(Option); + impl Drop for D { + fn drop(&mut self) { + if let Some(f) = self.0.take() { + f() + } + } + } + D(Some(f)) +} + #[repr(transparent)] pub struct JodChild(pub std::process::Child); -- cgit v1.2.3