diff options
author | Edwin Cheng <[email protected]> | 2021-01-07 17:08:34 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2021-01-07 17:08:34 +0000 |
commit | 54eb87de0363cfba1d7104b8d37898fc120c029b (patch) | |
tree | 938b927241824bda341d3699e24132d23aa7cde8 /crates | |
parent | 1347b7fa4cdc2064ac1cb4a686f10890b9235893 (diff) |
Refactor out JodChild
Diffstat (limited to 'crates')
-rw-r--r-- | crates/flycheck/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/flycheck/src/lib.rs | 23 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 23 |
3 files changed, 24 insertions, 23 deletions
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml index 3d9436d69..1bad64a1b 100644 --- a/crates/flycheck/Cargo.toml +++ b/crates/flycheck/Cargo.toml | |||
@@ -17,3 +17,4 @@ serde_json = "1.0.48" | |||
17 | jod-thread = "0.1.1" | 17 | jod-thread = "0.1.1" |
18 | 18 | ||
19 | toolchain = { path = "../toolchain", version = "0.0.0" } | 19 | toolchain = { path = "../toolchain", version = "0.0.0" } |
20 | stdx = { path = "../stdx", version = "0.0.0" } | ||
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index d982c5f29..4388e8c67 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs | |||
@@ -5,13 +5,13 @@ | |||
5 | use std::{ | 5 | use std::{ |
6 | fmt, | 6 | fmt, |
7 | io::{self, BufReader}, | 7 | io::{self, BufReader}, |
8 | ops, | ||
9 | path::PathBuf, | 8 | path::PathBuf, |
10 | process::{self, Command, Stdio}, | 9 | process::{self, Command, Stdio}, |
11 | time::Duration, | 10 | time::Duration, |
12 | }; | 11 | }; |
13 | 12 | ||
14 | use crossbeam_channel::{never, select, unbounded, Receiver, Sender}; | 13 | use crossbeam_channel::{never, select, unbounded, Receiver, Sender}; |
14 | use stdx::JodChild; | ||
15 | 15 | ||
16 | pub use cargo_metadata::diagnostic::{ | 16 | pub use cargo_metadata::diagnostic::{ |
17 | Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan, | 17 | Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan, |
@@ -323,24 +323,3 @@ impl CargoActor { | |||
323 | Ok(read_at_least_one_message) | 323 | Ok(read_at_least_one_message) |
324 | } | 324 | } |
325 | } | 325 | } |
326 | |||
327 | struct JodChild(process::Child); | ||
328 | |||
329 | impl ops::Deref for JodChild { | ||
330 | type Target = process::Child; | ||
331 | fn deref(&self) -> &process::Child { | ||
332 | &self.0 | ||
333 | } | ||
334 | } | ||
335 | |||
336 | impl ops::DerefMut for JodChild { | ||
337 | fn deref_mut(&mut self) -> &mut process::Child { | ||
338 | &mut self.0 | ||
339 | } | ||
340 | } | ||
341 | |||
342 | impl Drop for JodChild { | ||
343 | fn drop(&mut self) { | ||
344 | let _ = self.0.kill(); | ||
345 | } | ||
346 | } | ||
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 @@ | |||
1 | //! Missing batteries for standard libraries. | 1 | //! Missing batteries for standard libraries. |
2 | use std::time::Instant; | 2 | use std::{ops, process, time::Instant}; |
3 | 3 | ||
4 | mod macros; | 4 | mod macros; |
5 | pub mod panic_context; | 5 | pub mod panic_context; |
@@ -147,6 +147,27 @@ where | |||
147 | left | 147 | left |
148 | } | 148 | } |
149 | 149 | ||
150 | pub struct JodChild(pub process::Child); | ||
151 | |||
152 | impl ops::Deref for JodChild { | ||
153 | type Target = process::Child; | ||
154 | fn deref(&self) -> &process::Child { | ||
155 | &self.0 | ||
156 | } | ||
157 | } | ||
158 | |||
159 | impl ops::DerefMut for JodChild { | ||
160 | fn deref_mut(&mut self) -> &mut process::Child { | ||
161 | &mut self.0 | ||
162 | } | ||
163 | } | ||
164 | |||
165 | impl Drop for JodChild { | ||
166 | fn drop(&mut self) { | ||
167 | let _ = self.0.kill(); | ||
168 | } | ||
169 | } | ||
170 | |||
150 | #[cfg(test)] | 171 | #[cfg(test)] |
151 | mod tests { | 172 | mod tests { |
152 | use super::*; | 173 | use super::*; |