Skip to content

Commit

Permalink
Refactor out JodChild
Browse files Browse the repository at this point in the history
  • Loading branch information
edwin0cheng committed Jan 7, 2021
1 parent 1347b7f commit 54eb87d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/flycheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ serde_json = "1.0.48"
jod-thread = "0.1.1"

toolchain = { path = "../toolchain", version = "0.0.0" }
stdx = { path = "../stdx", version = "0.0.0" }
23 changes: 1 addition & 22 deletions crates/flycheck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use std::{
fmt,
io::{self, BufReader},
ops,
path::PathBuf,
process::{self, Command, Stdio},
time::Duration,
};

use crossbeam_channel::{never, select, unbounded, Receiver, Sender};
use stdx::JodChild;

pub use cargo_metadata::diagnostic::{
Applicability, Diagnostic, DiagnosticCode, DiagnosticLevel, DiagnosticSpan,
Expand Down Expand Up @@ -323,24 +323,3 @@ impl CargoActor {
Ok(read_at_least_one_message)
}
}

struct JodChild(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();
}
}
23 changes: 22 additions & 1 deletion crates/stdx/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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::*;
Expand Down

0 comments on commit 54eb87d

Please sign in to comment.