diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-19 22:59:22 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-20 23:34:15 +0800 |
| commit | c7a2788158628d3445f0f3574a0d7adfabd0a755 (patch) | |
| tree | 0c0e973b70f07cd4797b60bd17ca6d4b8e0f348d /src/client | |
| parent | 6511f6aaf68c3ab3bce10cdd743936b28e45dfa9 (diff) | |
init
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/connector.rs | 7 | ||||
| -rw-r--r-- | src/client/connector/httpconnector.rs | 4 | ||||
| -rw-r--r-- | src/client/executor.rs | 18 | ||||
| -rw-r--r-- | src/client/main.rs | 1 | ||||
| -rw-r--r-- | src/client/todo.md | 1 |
5 files changed, 7 insertions, 24 deletions
diff --git a/src/client/connector.rs b/src/client/connector.rs index d977ace..f57e388 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -6,11 +6,12 @@ use std::{ result, }; -use crate::{client::Client, executor::Executor}; -use remote_control_rs::tasks::NETWORK_T; +use crate::client::Client; +use remote_control_rs::{executor::Executor, tasks::NETWORK_T}; pub type Result<T: Display, E: Debug> = result::Result<T, E>; +// TODO: adapter to convert the types to strings so normal http server work too pub trait Connection { type Ok: std::fmt::Display + AsRef<str> = String; type Err: std::fmt::Debug; @@ -66,7 +67,7 @@ pub trait Connection { None => return, }; // FIXME: handle the errors... peak prod code - self.ntfy(Executor::new(task.try_into().unwrap(), it).unwrap().run().unwrap().clone().unwrap()).unwrap(); + self.ntfy(Executor::new(task.try_into().unwrap(), it).unwrap().run().as_ref().unwrap().clone()).unwrap(); } Result::Err(e) => { #[cfg(debug_assertions)] diff --git a/src/client/connector/httpconnector.rs b/src/client/connector/httpconnector.rs index dbd094c..60405f4 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::NETWORK_T; +use crate::connector::Connection; +use remote_control_rs::{executor::Executor, tasks::NETWORK_T}; use reqwest::{ Error, StatusCode, Url, blocking::{Client, RequestBuilder}, diff --git a/src/client/executor.rs b/src/client/executor.rs deleted file mode 100644 index 26ac0ba..0000000 --- a/src/client/executor.rs +++ /dev/null @@ -1,18 +0,0 @@ -use remote_control_rs::tasks::{IntoTaskErr, Task}; - -pub struct Executor<'a, '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, args: impl IntoIterator<Item = &'a str>) -> Result<Self, IntoTaskErr> { - Ok(Self { task: task, args: args.into_iter().collect(), output: None }) - } - - pub fn run(&mut self) -> Option<&Result<String, String>> { - self.output = Some((self.task.exec)(&self.args)); - self.output.as_ref() - } -} diff --git a/src/client/main.rs b/src/client/main.rs index be37341..0669197 100644 --- a/src/client/main.rs +++ b/src/client/main.rs @@ -10,7 +10,6 @@ use signal_hook::iterator::Signals; pub(crate) mod client; pub(crate) mod connector; -pub(crate) mod executor; fn main() { #[cfg(not(debug_assertions))] diff --git a/src/client/todo.md b/src/client/todo.md index 5f316b8..8c099ef 100644 --- a/src/client/todo.md +++ b/src/client/todo.md @@ -3,3 +3,4 @@ - [x] collect basic stuff - [ ] better typed task - [ ] websocket/SSE(streaming response) http server option +- [ ] multiple task at server |
