diff options
Diffstat (limited to 'src/client/executor')
| -rw-r--r-- | src/client/executor/tasks.rs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/client/executor/tasks.rs b/src/client/executor/tasks.rs index 148e262..3d9d940 100644 --- a/src/client/executor/tasks.rs +++ b/src/client/executor/tasks.rs @@ -1,4 +1,4 @@ -pub(crate) struct Task { +pub struct Task { pub name: &'static str, pub exec: fn(&[String]) -> Result<String, String>, } @@ -9,7 +9,7 @@ impl PartialEq for &Task { } } -pub(crate) const TASKS: &[Task] = &[ +pub const TASKS: &[Task] = &[ Task { name: "nop", exec: no_op, @@ -34,13 +34,9 @@ fn exec(cmds: &[String]) -> Result<String, String> { match Command::new(cmds[0].as_str()).args(&cmds[1..]).output() { Ok(o) => { if o.status.success() { - Ok(String::from_utf8(o.stdout) - .unwrap_or("Failed decoding vec<u8> -> String".to_string()) - .to_string()) + Ok(String::from_utf8_lossy(&o.stdout).to_string()) } else { - Err(String::from_utf8(o.stderr) - .unwrap_or("Failed decoding vec<u8> -> String".to_string()) - .to_string()) + Err(String::from_utf8_lossy(&o.stderr).to_string()) } } Err(e) => Err(e.to_string()), @@ -112,12 +108,10 @@ fn network(switch: &[String]) -> Result<String, String> { ).arg(if switch { "on" } else { "off" }).output() { Ok(o) => { if o.status.success() { - Ok(String::from_utf8(o.stdout) - .unwrap_or("Failed decoding vec<u8> -> String".to_string()) + Ok(String::from_utf8_lossy(&o.stdout) .to_string()) } else { - Err(String::from_utf8(o.stderr) - .unwrap_or("Failed decoding vec<u8> -> String".to_string()) + Err(String::from_utf8_lossy(&o.stderr) .to_string()) } } @@ -135,11 +129,11 @@ fn network(switch: &[String]) -> Result<String, String> { } #[derive(Debug)] -pub(crate) enum IntoTaskErr { +pub enum IntoTaskErr { NotFound(String), } -pub(crate) trait IntoTask { +pub trait IntoTask { fn into_task<'a>(self) -> Result<&'a Task, IntoTaskErr>; } |
