From 54eb87de0363cfba1d7104b8d37898fc120c029b Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 8 Jan 2021 01:08:34 +0800 Subject: Refactor out JodChild --- crates/stdx/src/lib.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/stdx') diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 374ed5910..5332edb09 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -1,5 +1,5 @@ //! Missing batteries for standard libraries. -use std::time::Instant; +use std::{ops, process, time::Instant}; mod macros; pub mod panic_context; @@ -147,6 +147,27 @@ where left } +pub struct JodChild(pub process::Child); + +impl ops::Deref for JodChild { + type Target = process::Child; + fn deref(&self) -> &process::Child { + &self.0 + } +} + +impl ops::DerefMut for JodChild { + fn deref_mut(&mut self) -> &mut process::Child { + &mut self.0 + } +} + +impl Drop for JodChild { + fn drop(&mut self) { + let _ = self.0.kill(); + } +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3