From 3c97b8ee7421b45b44676a7455c5a84f849db9af Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 5 Dec 2021 21:52:30 +0500 Subject: [PATCH] Remove unnecessary code --- src/task.rs | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/task.rs b/src/task.rs index 3377740..8ec9d2f 100644 --- a/src/task.rs +++ b/src/task.rs @@ -22,25 +22,12 @@ impl TaskConfig { pub fn new>(exe: Exe) -> Self { Self { exe: exe.into() } } - - pub fn exe(&self) -> &String { - &self.exe - } } impl TaskInfo { pub fn new(config: TaskConfig, pid: libc::pid_t) -> Self { Self { config, pid } } - - #[allow(dead_code)] - pub fn config(&self) -> &TaskConfig { - &self.config - } - - pub fn pid(&self) -> libc::pid_t { - self.pid - } } impl TaskResult { @@ -48,11 +35,6 @@ impl TaskResult { Self { info, status } } - #[allow(dead_code)] - pub fn info(&self) -> &TaskInfo { - &self.info - } - pub fn status(&self) -> i32 { self.status } @@ -71,7 +53,7 @@ pub trait Task: Debug + Sized { } if pid == 0 { - let arg0 = CString::new(config.exe().as_bytes()).unwrap(); + let arg0 = CString::new(config.exe.as_bytes()).unwrap(); let args = vec![arg0.as_ptr(), std::ptr::null()]; libc::execvp(arg0.as_ptr(), args.as_ptr()); libc::exit(libc::EXIT_FAILURE); @@ -84,7 +66,7 @@ pub trait Task: Debug + Sized { fn wait(self) -> TaskResult { unsafe { let status: i32 = 0; - libc::waitpid(self.info().pid(), status as *mut i32, 0); + libc::waitpid(self.info().pid, status as *mut i32, 0); let status = libc::WEXITSTATUS(status); TaskResult::new(self.info().clone(), status) } @@ -92,9 +74,9 @@ pub trait Task: Debug + Sized { fn terminate(self) -> TaskResult { unsafe { - libc::kill(self.info().pid(), libc::SIGKILL); + libc::kill(self.info().pid, libc::SIGKILL); let status: i32 = 0; - libc::waitpid(self.info().pid(), status as *mut i32, 0); + libc::waitpid(self.info().pid, status as *mut i32, 0); let status = libc::WEXITSTATUS(status); TaskResult::new(self.info().clone(), status) }