From b7bc239c47d419ea5c5b078b89ca11def6c7311b Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Wed, 17 Sep 2025 19:24:00 +0800 Subject: perf: more prevalent &str --- src/tasks.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tasks.rs') diff --git a/src/tasks.rs b/src/tasks.rs index 3c49c7a..9175214 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -1,6 +1,6 @@ pub struct Task<'a> { pub name: &'a str, - pub exec: fn(&[String]) -> Result, + pub exec: fn(&[&str]) -> Result, } impl<'a> PartialEq for &'a Task<'a> { @@ -13,15 +13,15 @@ pub const TASKS: &[Task<'static>] = &[Task { name: "nop", exec: no_op }, Task { pub const NETWORK_T: Task<'static> = Task { name: "network", exec: network }; -fn no_op(_: &[String]) -> Result { +fn no_op(_: &[&str]) -> Result { Ok("".to_string()) } -fn exec(cmds: &[String]) -> Result { +fn exec(cmds: &[&str]) -> Result { use std::process::Command; // TODO: fmt and add exit code, and add support for both stdout and stderr, and // support for no output - match Command::new(cmds[0].as_str()).args(&cmds[1..]).output() { + match Command::new(cmds[0]).args(&cmds[1..]).output() { Ok(o) => { if o.status.success() { Ok(String::from_utf8_lossy(&o.stdout).to_string()) @@ -33,7 +33,7 @@ fn exec(cmds: &[String]) -> Result { } } -fn network(switch: &[String]) -> Result { +fn network(switch: &[&str]) -> Result { use std::process::{Command, Stdio}; let switch: bool = switch[0].parse::().map_err(|e| e.to_string())?; @@ -112,7 +112,7 @@ pub enum IntoTaskErr { NotFound(String), } -impl<'a> TryFrom<&str> for &'a Task<'a> { +impl TryFrom<&str> for &'static Task<'static> { type Error = IntoTaskErr; fn try_from(value: &str) -> Result { -- cgit v1.2.3