Ownership and cleanup
A tmux session, window, or pane normally remains until you kill it. Scope-based cleanup can kill it when your code leaves a block, including after an exception. See Workspaces for a temporary layout example.
Explicit asynchronous cleanup¶
Rust’s Drop is synchronous and cannot await an async tmux kill. Use
explicit shutdown when you need to observe cleanup failures:
kill(self)consumes the handle. Session, window, and pane kill methods takeselfby value, preventing subsequent use of that handle.libtmux::test::TestServerprovides a test guard. CallTestServer.shutdownto handle cleanup errors. ItsDropimplementation makes a synchronous cleanup attempt.
use libtmux::test::TestServer;
let guard = TestServer::new().await?;let server = guard.server();
let session = server.new_session("work").await?;session.new_window("editor").await?;
// Await shutdown to handle cleanup errors.guard.shutdown().await?;Testing cleanup¶
Use explicit cleanup for objects whose handles have no disposal hook. For an entire disposable test server, prefer your port’s test fixture or server guard; see Testing with libtmux.