From 824f5b52f51931c768ec789dcd80a7e0e956b177 Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Mon, 15 Jul 2024 12:44:56 +0200 Subject: [PATCH] panic if dropped without being terminated --- input-capture/src/libei.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/input-capture/src/libei.rs b/input-capture/src/libei.rs index 67c0c17..959f634 100644 --- a/input-capture/src/libei.rs +++ b/input-capture/src/libei.rs @@ -60,6 +60,7 @@ pub struct LibeiInputCapture<'a> { notify_capture: Sender, notify_release: Arc, cancellation_token: CancellationToken, + terminated: bool, } static INTERFACES: Lazy> = Lazy::new(|| { @@ -222,6 +223,7 @@ impl<'a> LibeiInputCapture<'a> { notify_capture, notify_release, cancellation_token, + terminated: false, }; Ok(producer) @@ -548,10 +550,19 @@ impl<'a> LanMouseInputCapture for LibeiInputCapture<'a> { log::debug!("waiting for capture to terminate..."); let res = task.await.expect("libei task panic"); log::debug!("done!"); + self.terminated = true; res } } +impl<'a> Drop for LibeiInputCapture<'a> { + fn drop(&mut self) { + if !self.terminated { + panic!("LibeiInputCapture dropped without being terminated!"); + } + } +} + impl<'a> Stream for LibeiInputCapture<'a> { type Item = Result<(CaptureHandle, Event), CaptureError>;