From 83e5044fd6e5c2a8bccd29f5a8462e7016823aed Mon Sep 17 00:00:00 2001 From: Jonas Maier <> Date: Tue, 10 Mar 2026 15:00:44 +0100 Subject: defer macro --- src/export_fun.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/export_fun.rs') diff --git a/src/export_fun.rs b/src/export_fun.rs index ecbdf46..a98699c 100644 --- a/src/export_fun.rs +++ b/src/export_fun.rs @@ -5,6 +5,7 @@ use nix::poll::PollFlags; use nix::poll::poll; use crate::Session; +use crate::defer; use crate::run::Input; use crate::run::Output; use crate::run::get_command_kind; @@ -32,7 +33,6 @@ use std::sync::Arc; use std::sync::Mutex; use std::sync::mpsc; use std::sync::mpsc::Receiver; -use std::sync::mpsc::Sender; use std::thread; use std::time::Duration; @@ -204,7 +204,9 @@ impl Drop for SocketDropper { // wait 1s for background to exit if let Err(e) = sr.recv.recv_timeout(Duration::from_secs(1)) { - eprintln!("background thread is still running({e:?}, session might not be cleaned up\r"); + eprintln!( + "background thread is still running({e:?}, session might not be cleaned up\r" + ); } } } @@ -231,19 +233,9 @@ pub fn listen(session: Arc>) -> impl Drop { let se = session.clone(); thread::spawn(move || { - struct SessionRemover { - send: Sender<()>, - path: PathBuf, - } - impl Drop for SessionRemover { - fn drop(&mut self) { - let _ = fs::remove_dir_all(&self.path); - let _ = self.send.send(()); - } - } - let _session_remover = SessionRemover { - path: session_dir, - send, + defer! { + let _ = fs::remove_dir_all(session_dir); + let _ = send.send(()); }; let listener = UnixListener::bind(socket_path).unwrap(); -- cgit v1.2.3