Skip to content

Commit 9553137

Browse files
committed
Code style
1 parent 3d71647 commit 9553137

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

tmc-langs-framework/src/command.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! Custom wrapper for Command that supports timeouts and contains custom error handling.
22
33
use crate::{error::CommandError, TmcError};
4-
use std::{fmt, sync::Mutex};
4+
use os_pipe::pipe;
5+
#[cfg(unix)]
6+
use shared_child::unix::SharedChildExt;
7+
use shared_child::SharedChild;
58
use std::io::Read;
69
use std::ops::{Deref, DerefMut};
710
use std::path::PathBuf;
811
use std::process::{Command, ExitStatus, Output};
9-
use shared_child::SharedChild;
1012
use std::sync::Arc;
1113
use std::thread;
12-
use std::time::{Duration};
13-
use os_pipe::pipe;
14-
#[cfg(unix)]
15-
use shared_child::unix::SharedChildExt;
14+
use std::time::Duration;
15+
use std::{fmt, sync::Mutex};
1616

1717
// todo: collect args?
1818
#[derive(Debug)]
@@ -123,8 +123,7 @@ impl TmcCommand {
123123

124124
let (process_result, timed_out) = {
125125
let mut command = self.command;
126-
command.stdout(stdout_writer)
127-
.stderr(stderr_writer);
126+
command.stdout(stdout_writer).stderr(stderr_writer);
128127

129128
let shared_child = SharedChild::spawn(&mut command)
130129
.map_err(|e| TmcError::Command(CommandError::Spawn(self_string, e)))?;
@@ -134,7 +133,6 @@ impl TmcCommand {
134133
let running_clone = running.clone();
135134
let timed_out = Arc::new(Mutex::new(false));
136135

137-
138136
let child_arc_clone = child_arc.clone();
139137
let timed_out_clone = timed_out.clone();
140138
let _timeout_checker = thread::spawn(move || {
@@ -167,8 +165,6 @@ impl TmcCommand {
167165
// before we read, otherwise the read end will never report EOF.
168166
// The block above drops everything unnecessary
169167

170-
171-
172168
let res = match process_result {
173169
Ok(exit_status) => {
174170
let mut stdout = vec![];
@@ -180,7 +176,11 @@ impl TmcCommand {
180176
.read_to_end(&mut stderr)
181177
.map_err(TmcError::ReadStdio)?;
182178

183-
Output { status: exit_status, stdout: stdout, stderr: stderr}
179+
Output {
180+
status: exit_status,
181+
stdout: stdout,
182+
stderr: stderr,
183+
}
184184
}
185185
Err(e) => {
186186
if let std::io::ErrorKind::NotFound = e.kind() {
@@ -190,13 +190,19 @@ impl TmcCommand {
190190
source: e,
191191
}));
192192
} else {
193-
return Err(TmcError::Command(CommandError::FailedToRun(self_string2, e)));
193+
return Err(TmcError::Command(CommandError::FailedToRun(
194+
self_string2,
195+
e,
196+
)));
194197
}
195198
}
196199
};
197200

198201
if timed_out.lock().unwrap().clone() {
199-
return Ok(OutputWithTimeout::Timeout { stdout: res.stdout, stderr: res.stderr});
202+
return Ok(OutputWithTimeout::Timeout {
203+
stdout: res.stdout,
204+
stderr: res.stderr,
205+
});
200206
}
201207

202208
return Ok(OutputWithTimeout::Output(res));

0 commit comments

Comments
 (0)