From 888b6879767568179c024597e6b76cfb9871b639 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Sat, 2 Aug 2025 18:48:36 +0800 Subject: [PATCH 1/3] Run cargo fmt --all --- examples/dd_test.rs | 2 +- rustfmt.toml | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 rustfmt.toml diff --git a/examples/dd_test.rs b/examples/dd_test.rs index 2415836..e68ebcd 100644 --- a/examples/dd_test.rs +++ b/examples/dd_test.rs @@ -15,10 +15,10 @@ //! [INFO ] Total bandwidth: 1.11 GiB/s //! ``` use byte_unit::Byte; +use clap::Parser; use cmd_lib::*; use rayon::prelude::*; use std::time::Instant; -use clap::Parser; const DATA_SIZE: u64 = 10 * 1024 * 1024 * 1024; // 10GB data diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..e69de29 From 1c49fd23ce7754ea34eaf50f810efcb2f39416f6 Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Sat, 2 Aug 2025 15:37:02 +0800 Subject: [PATCH 2/3] Clean up Cmds by eliminating unnecessary Option --- src/process.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/process.rs b/src/process.rs index 11d84ee..d21ad3b 100644 --- a/src/process.rs +++ b/src/process.rs @@ -11,6 +11,7 @@ use std::ffi::{OsStr, OsString}; use std::fmt; use std::fs::{File, OpenOptions}; use std::io::{Error, ErrorKind, Result}; +use std::mem::take; use std::path::{Path, PathBuf}; use std::process::Command; use std::sync::Mutex; @@ -160,7 +161,7 @@ impl GroupCmds { #[doc(hidden)] #[derive(Default)] pub struct Cmds { - cmds: Vec>, + cmds: Vec, full_cmds: String, ignore_error: bool, file: String, @@ -188,7 +189,7 @@ impl Cmds { ); } } - self.cmds.push(Some(cmd)); + self.cmds.push(cmd); self } @@ -204,8 +205,7 @@ impl Cmds { let mut children: Vec = Vec::new(); let len = self.cmds.len(); let mut prev_pipe_in = None; - for (i, cmd_opt) in self.cmds.iter_mut().enumerate() { - let mut cmd = cmd_opt.take().unwrap(); + for (i, mut cmd) in take(&mut self.cmds).into_iter().enumerate() { if i != len - 1 { // not the last, update redirects let (pipe_reader, pipe_writer) = From c69d26f2d1608eebf1edee68827934715987678c Mon Sep 17 00:00:00 2001 From: Delan Azabani Date: Sat, 2 Aug 2025 18:39:04 +0800 Subject: [PATCH 3/3] Remove dead code in StderrThread::new() --- src/child.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/child.rs b/src/child.rs index 6e4f73d..07c7f54 100644 --- a/src/child.rs +++ b/src/child.rs @@ -354,14 +354,10 @@ impl StderrThread { .lines() .map_while(Result::ok) .for_each(|line| { - if !capture { - info!("{line}"); - } else { - if !output.is_empty() { - output.push('\n'); - } - output.push_str(&line); + if !output.is_empty() { + output.push('\n'); } + output.push_str(&line); }); return output; }