diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-15 14:59:12 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-17 21:28:52 +0800 |
| commit | 84e3f12e6c1b3258defab2a08497489c25f48c65 (patch) | |
| tree | 80c09911c8ee5be28f2a3c487d15e6ac38bb89a7 | |
| parent | b4faad42e862031617924d08de53a56bfe3b966e (diff) | |
feat: use typed network task
| -rw-r--r-- | src/client/connector/httpconnector.rs | 6 | ||||
| -rw-r--r-- | 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<Self, url::ParseError> { - // 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<String, String> { Ok("".to_string()) } |
