From 84e3f12e6c1b3258defab2a08497489c25f48c65 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 15 Sep 2025 14:59:12 +0800 Subject: feat: use typed network task --- src/client/connector/httpconnector.rs | 6 ++---- src/tasks.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs index b8369fe..d8c0027 100644 --- a/src/client/connector/httpconnector.rs +++ b/src/client/connector/httpconnector.rs @@ -1,5 +1,5 @@ use crate::{connector::Connection, executor::Executor}; -use remote_control_rs::tasks::TASKS; +use remote_control_rs::tasks::NETWORK_T; use reqwest::{ Error, StatusCode, Url, blocking::{Client, RequestBuilder}, @@ -21,10 +21,8 @@ impl HTTPConnector { ntfy_url: &str, ip_getter_url: &str, ) -> std::result::Result { - // TODO: proper type - assert_eq!(TASKS[2].name, "network"); Ok(Self { - network_enforcer: Executor::new(&TASKS[2], ["on".to_string()]).unwrap(), // .unwrap() should never panic + network_enforcer: Executor::new(&NETWORK_T, ["on".to_string()]).unwrap(), // .unwrap() should never panic prev: String::new(), pull_url: Url::parse(pull_url)?, ntfy_url: Url::parse(ntfy_url)?, diff --git a/src/tasks.rs b/src/tasks.rs index 3d9d940..e9ce6bd 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -18,12 +18,14 @@ pub const TASKS: &[Task] = &[ name: "exec", exec: exec, }, - Task { - name: "network", - exec: network, - }, + NETWORK_T, ]; +pub const NETWORK_T: Task = Task { + name: "network", + exec: network, +}; + fn no_op(_: &[String]) -> Result { Ok("".to_string()) } -- cgit v1.2.3