summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/executor.rs4
-rw-r--r--src/tasks.rs25
2 files changed, 18 insertions, 11 deletions
diff --git a/src/client/executor.rs b/src/client/executor.rs
index b75040a..26ac0ba 100644
--- a/src/client/executor.rs
+++ b/src/client/executor.rs
@@ -1,13 +1,13 @@
use remote_control_rs::tasks::{IntoTaskErr, Task};
pub struct Executor<'a, 't> {
- task: &'a Task<'t>,
+ task: &'t Task,
args: Box<[&'a str]>,
output: Option<Result<String, String>>,
}
impl<'a, 't> Executor<'a, 't> {
- pub fn new(task: &'t Task<'t>, args: impl IntoIterator<Item = &'a str>) -> Result<Self, IntoTaskErr> {
+ pub fn new(task: &'t Task, args: impl IntoIterator<Item = &'a str>) -> Result<Self, IntoTaskErr> {
Ok(Self { task: task, args: args.into_iter().collect(), output: None })
}
diff --git a/src/tasks.rs b/src/tasks.rs
index 9175214..e862f79 100644
--- a/src/tasks.rs
+++ b/src/tasks.rs
@@ -1,17 +1,24 @@
-pub struct Task<'a> {
- pub name: &'a str,
+pub struct Task {
+ pub name: Name,
pub exec: fn(&[&str]) -> Result<String, String>,
}
-impl<'a> PartialEq for &'a Task<'a> {
- fn eq(&self, other: &Self) -> bool {
- self.name == other.name
+#[derive(Debug)]
+pub enum Name {
+ Nop,
+ Exec,
+ Network,
+}
+
+impl std::fmt::Display for Name {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "{:?}", self)
}
}
-pub const TASKS: &[Task<'static>] = &[Task { name: "nop", exec: no_op }, Task { name: "exec", exec: exec }, NETWORK_T];
+pub const TASKS: &[Task] = &[Task { name: Name::Nop, exec: no_op }, Task { name: Name::Exec, exec: exec }, NETWORK_T];
-pub const NETWORK_T: Task<'static> = Task { name: "network", exec: network };
+pub const NETWORK_T: Task = Task { name: Name::Network, exec: network };
fn no_op(_: &[&str]) -> Result<String, String> {
Ok("".to_string())
@@ -112,12 +119,12 @@ pub enum IntoTaskErr {
NotFound(String),
}
-impl TryFrom<&str> for &'static Task<'static> {
+impl TryFrom<&str> for &'static Task {
type Error = IntoTaskErr;
fn try_from(value: &str) -> Result<Self, Self::Error> {
for task in TASKS {
- if task.name == value {
+ if task.name.to_string() == value {
return Ok(task);
}
}