Skip to content

Commit 2eb19ae

Browse files
authored
Merge pull request #81 from delan/cleanup
Minor cleanups
2 parents f0c102c + c69d26f commit 2eb19ae

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

examples/dd_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
//! [INFO ] Total bandwidth: 1.11 GiB/s
1616
//! ```
1717
use byte_unit::Byte;
18+
use clap::Parser;
1819
use cmd_lib::*;
1920
use rayon::prelude::*;
2021
use std::time::Instant;
21-
use clap::Parser;
2222

2323
const DATA_SIZE: u64 = 10 * 1024 * 1024 * 1024; // 10GB data
2424

rustfmt.toml

Whitespace-only changes.

src/child.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,10 @@ impl StderrThread {
354354
.lines()
355355
.map_while(Result::ok)
356356
.for_each(|line| {
357-
if !capture {
358-
info!("{line}");
359-
} else {
360-
if !output.is_empty() {
361-
output.push('\n');
362-
}
363-
output.push_str(&line);
357+
if !output.is_empty() {
358+
output.push('\n');
364359
}
360+
output.push_str(&line);
365361
});
366362
return output;
367363
}

src/process.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::ffi::{OsStr, OsString};
1111
use std::fmt;
1212
use std::fs::{File, OpenOptions};
1313
use std::io::{Error, ErrorKind, Result};
14+
use std::mem::take;
1415
use std::path::{Path, PathBuf};
1516
use std::process::Command;
1617
use std::sync::Mutex;
@@ -160,7 +161,7 @@ impl GroupCmds {
160161
#[doc(hidden)]
161162
#[derive(Default)]
162163
pub struct Cmds {
163-
cmds: Vec<Option<Cmd>>,
164+
cmds: Vec<Cmd>,
164165
full_cmds: String,
165166
ignore_error: bool,
166167
file: String,
@@ -188,7 +189,7 @@ impl Cmds {
188189
);
189190
}
190191
}
191-
self.cmds.push(Some(cmd));
192+
self.cmds.push(cmd);
192193
self
193194
}
194195

@@ -204,8 +205,7 @@ impl Cmds {
204205
let mut children: Vec<CmdChild> = Vec::new();
205206
let len = self.cmds.len();
206207
let mut prev_pipe_in = None;
207-
for (i, cmd_opt) in self.cmds.iter_mut().enumerate() {
208-
let mut cmd = cmd_opt.take().unwrap();
208+
for (i, mut cmd) in take(&mut self.cmds).into_iter().enumerate() {
209209
if i != len - 1 {
210210
// not the last, update redirects
211211
let (pipe_reader, pipe_writer) =

0 commit comments

Comments
 (0)