summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-20 23:40:49 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-20 23:40:49 +0800
commit3fa4e33421e3fa94ca63ceb99856f97f9aac741a (patch)
tree8f1a90f6ac95e93d9e2266ae5e2d82b11e5b21ec /src
parent6ba037fe8810b64a47cbf9baa0f914e08719e6dc (diff)
wip ctx
Diffstat (limited to 'src')
-rw-r--r--src/tasks.rs4
-rw-r--r--src/tasks/server.rs46
2 files changed, 48 insertions, 2 deletions
diff --git a/src/tasks.rs b/src/tasks.rs
index 3e76ce4..069f9c2 100644
--- a/src/tasks.rs
+++ b/src/tasks.rs
@@ -4,9 +4,9 @@ pub type TaskOutput = Result<String, String>;
pub mod client;
pub mod server;
-pub struct Task<N> {
+pub struct Task<N, T = ()> {
pub name: N,
- pub exec: fn(&[&str]) -> TaskOutput,
+ pub exec: fn(&[&str], T) -> TaskOutput,
}
#[derive(Deserialize)]
diff --git a/src/tasks/server.rs b/src/tasks/server.rs
index e69de29..0896dca 100644
--- a/src/tasks/server.rs
+++ b/src/tasks/server.rs
@@ -0,0 +1,46 @@
+use std::fmt::Display;
+
+use crate::tasks::{IntoTaskErr, Task as BaseTask, TaskOutput};
+use serde::Deserialize;
+
+pub struct Task<T = ()>(pub BaseTask<Name, T>);
+
+#[derive(Debug, Deserialize, Clone, Copy)]
+pub enum Name {
+ GetIp,
+}
+
+impl Display for Name {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "{:?}", self)
+ }
+}
+
+pub const TASKS: &[Task] = &[Task::<i32>(BaseTask { name: Name::GetIp, exec: get_ip })];
+
+fn get_ip(cmds: &[&str], _: i32) -> TaskOutput {}
+
+impl TryFrom<&str> for &'static Task {
+ type Error = IntoTaskErr;
+
+ fn try_from(value: &str) -> Result<Self, Self::Error> {
+ for task in TASKS {
+ if task.0.name.to_string() == value {
+ return Ok(task);
+ }
+ }
+ Err(IntoTaskErr::NotFound(value.to_string()))
+ }
+}
+
+impl From<Task> for BaseTask<Name> {
+ fn from(value: Task) -> Self {
+ value.0
+ }
+}
+
+impl AsRef<BaseTask<Name>> for Task {
+ fn as_ref(&self) -> &BaseTask<Name> {
+ &self.0
+ }
+}